I have an array of objects of my base class, Customer. It has 3 sub-classes Account1, Account2 and acount3. When i run through a loop checking every account for its type and then assigning it appropriately, in the end i just get empty data fields.
Is something like this possible to do?
public static int readFile(String filename, Customer[] review)throws IOException{
Scanner scan = new Scanner (new File (filename));
/*Reading the first record separatly*/
Customer first = new Customer();
Account1 first1= new Account1();
Account2 first2= new Account2();
Account3 first3 = new Account3();
String[] a = scan.nextLine().split("=");
first.set_account_id(Integer.parseInt(a[1].trim()));
a = scan.nextLine().split("=");
first.set_name(a[1].toUpperCase().trim());
a = scan.nextLine().split("=");
first.set_address(a[1].trim());
a= scan.nextLine().split("=");
first.set_accType(a[1].trim());
if (first.get_accType().equals("Saving")){
first = first1;
}
else if(first.get_accType().equals("Checking")){
first = first2;
}
else if(first.get_accType().equals("Fixed")){
first = first3;
a = scan.nextLine().split("=");
first3.set_intRate(Double.parseDouble(a[1].trim()));
}
This code gives me empty data fields for my objects..