java - Loading information from file in different ways -
my program has working:
bank bank = new bank(); bank.openaccount(new checkingaccount(10100, new customer("first", "last"),500.00,false)); bank.openaccount(new checkingaccount(10101, new customer("first", "last"),2000.00,true)); bank.openaccount(new savingsaccount(2010, new customer("first", "last"),5000.00,0.02));
now trying load information file instead, ran bit of wall. want new customer information include both first , last name stored in separate index positions separate variables, while work:
new customer[first_index],
i can't seem accept 2 index positions without creating new customer again. turn causing issue method in accounts i'd keep same format. how can go doing this?
public checkingaccount(int accountnumber, customer owner, double currentbalance, boolean freechecks) { super(accountnumber, owner, currentbalance); this.freechecks = freechecks; }
another problem running last index position can 1 of 2 variables depending on if dealing checking account or savings account:
private final static int free_checks_index = 4; // loads boolean private final static int interest_index = 4; // loads double
given this, i'm not entirely sure if above approach work @ all. program supposed load either checking account or savings account object, since both types of accounts stored in same file wondering if read last index position of each line of text file before creating object, i'm not sure how go doing that.
to clear, have problem working without loading data file, unsure best approach adapting without having rewrite other classes. here's new thing trying know isn't right:
protected static void loadaccountinformationfromfile() throws exception { try ( scanner fin = new scanner(new file(input_customer_file)) ) { string record; string[] fields; while ( fin.hasnext() ) { record = fin.nextline(); fields = record.split(","); bank bank = new bank(); bank.openaccount ( new checkingaccount(integer.parseint(accountnumber[account_number_index]), new customer[first_index, last_index], currentbalance[balance_index], freechecks[free_checks_index] ) ); } } catch (exception e) { throw e; } // end try }
Comments
Post a Comment