/** * The test class InputData. * * @author (your name) * @version (a version number or a date) */ import java.util.*; import java.io.*; import javax.swing.*; public class InputData { public InputData() { } public int getInputAsAscii(File file,BankAccount [] acc) { String line; StringTokenizer tokenizer; int n = 0; //n try { FileReader fr = new FileReader(file); BufferedReader inFile = new BufferedReader(fr); //create temp variables for all possible inputs String tempName; double tempInitial,tempInterestRate,tempMinimumAmount,tempMinimumBalance,tempFee; int key; // key = 1, checking // key = 2, savings // key = 3, money market line = inFile.readLine(); while(line != null) { tokenizer = new StringTokenizer(line); try { key = Integer.parseInt(tokenizer.nextToken()); //create new account in the list of accounts (acc) tempName = tokenizer.nextToken(); switch(key) { case 1: tempInitial = Double.parseDouble(tokenizer.nextToken());1 tempFee= Double.parseDouble(tokenizer.nextToken());1 acc[n] = new Checking(tempName,tempInitial,tempFee); n++; break; case 2: tempInitial = Double.parseDouble(tokenizer.nextToken()); tempInterestRate = Double.parseDouble(tokenizer.nextToken()); acc[n++] = new Savings(tempName,tempInitial, tempInterestRate); break; case 3: tempInitial = Double.parseDouble(tokenizer.nextToken()); tempInterestRate = Double.parseDouble(tokenizer.nextToken()); tempMinimumAmount = Double.parseDouble(tokenizer.nextToken()); tempMinimumBalance = Double.parseDouble(tokenizer.nextToken()); acc[n++] = new MoneyMarket(tempName,tempInitial, tempInterestRate,tempMinimumAmount,tempMinimumBalance); break; default: System.out.println("Error in input. Line " + "ignored: " + line); } } catch(NumberFormatException exception) { System.out.println("Error in input. Line ignored: " +line); } //read and inserted one new element. get the next element line = inFile.readLine(); }//end of input reads inFile.close(); } catch(FileNotFoundException exception) { JOptionPane.showMessageDialog(null,"The file " + file.getAbsolutePath() + " was not found.","File not Found",JOptionPane.ERROR_MESSAGE); System.exit(0); } catch(IOException exception) { System.out.println(exception); System.exit(0); } return n; }//end of getInput }