Ok, so I have to write a program for school that will read data from a text file, split the data (comma delimited) into the correct type, pass that information on to a class, store the class object into an array.
This is what I have so far:
import java.io.*;
public class BankTest{
public static void main(String [] args)throws IOException{
/* ********************************************************
*
* This was the first exercise to send data to the
* BankAccount class.
*
BankAccount ba1 = new BankAccount();
BankAccount ba2 = new BankAccount(135687, "chris servin",
100.0,false);
System.out.println(ba1.getOwner());
System.out.println(ba1.getExperiation());
System.out.println(ba2.getOwner());
System.out.println(ba2.getExperiation());
System.out.println(ba2.getBalance());
ba2.deposit(200.0);
System.out.println (ba2.getStatus());
System.out.println(ba2.getBalance());
ba2.withdrawl(100.0);
System.out.println(ba2.getBalance());
System.out.println(ba2.toString());
***********************************************************
*/
int size;
String str;
String db[];
BufferedReader input = new BufferedReader(new FileReader("database.txt"));
str = input.readLine();
size = Integer.parseInt(str);
db = new String[size];
str = input.readLine();
//System.out.println(db);
for (int i = 0; i < size; i++){
String[] info = str.split(",");
//BankAccount ba(i) = new BankAccount();
BankAccount ba = new BankAccount(int info[0], String info[1],
double [2], boolean [3]);
//System.out.println(info);
str = input.readLine();
}
}
}
Now I don't want too much help writing this, but I am stuck, I have 2 errors that keep coming up that I just can't figure out how to solve.
The first is if I use the statement
BankAccount ba(i) = new BankAccount();
I get - Error: D:\EPCC AA Computer Science\Spring Semester 2011\Java 2\Programs\BankTest.java:49: ';' expected
The second error I get if I remove the (i) variable (which I wanted to create individual instances of the ba object is:
Error: D:\EPCC AA Computer Science\Spring Semester 2011\Java 2\Programs\BankTest.java:51: '.class' expected
I am getting this error on the line where I am attempting to pass the elements in the info array created in the line.split statement.
Can someone please help, I'm at a loss as to how to accomplish what I am trying to get done.
Thanks