I am creating a program like Mint.
right now, I am getting information from a text file, splitting it by the spaces, then going to pass it to the Constructor of another class to create objects. I am having a bit of trouble getting that done properly.
I don't know how to get the information I actually need from the text file with all the extra stuff that's in it.
I need to have an array of objects that has 100 spots. The Constructor is
public Expense (int cN, String desc, SimpleDateFormat dt, double amt, boolean repeat)
The file comes as :
(0,"Cell Phone Plan", new SimpleDateFormat("08/15/2015"), 85.22, true);
(0,"Car Insurance", new SimpleDateFormat("08/05/2015"), 45.22, true);
(0,"Office Depot - filing cabinet", new SimpleDateFormat("08/31/2015"), 185.22, false);
(0,"Gateway - oil change", new SimpleDateFormat("08/29/2015"), 35.42, false);
Below is my code for the main:
Expense expense[] = new Expense[100];
Expense e = new Expense();
int catNum;
String name;
SimpleDateFormat date = new SimpleDateFormat("01/01/2015");
double price;
boolean monthly;
try {
File file = new File("expenses.txt");
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String array[] = line.split(",");
expenses[i] = new Expense(catNum, name, date, price, monthly);
}
scanner.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
new SimpleDateFormat("01/01/2015")is probably wrong, should benew SimpleDateFormat("dd-MM-yyyy").Integer.parseInt(String)etc to convert from strings to the arguments of your constructor