SHARE
TWEET

Untitled

a guest Mar 20th, 2017 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * File: BankDriver.java
  3.  * Description: Demonstrates polymorphism and inheritance
  4.  * Dependencies: Bank, Account, Transactions, CheckingAccount, SavingsAccount <, IRAAccount>
  5.  *
  6.  * @author Patty Kraft
  7.  */
  8. import java.io.BufferedReader;
  9. import java.io.FileReader;
  10. import java.io.File;
  11. import java.io.FileNotFoundException;
  12. import java.io.IOException;
  13. import java.util.ArrayList;
  14. import java.util.Scanner;
  15.  
  16.  
  17. public class BankDriver {
  18.    
  19.     public static void main(String[] args) {
  20.         Bank bank = new Bank();
  21.        
  22.         Scanner infile = new Scanner("customers.csv");
  23.         while (infile.hasNextLine() ) {
  24.            Scanner s2 = new Scanner(infile.nextLine()); // put string from file into second Scanner object
  25.            s2.useDelimiter(",");
  26.            if (s2.hasNextInt()) {
  27.               int type = s2.nextInt();
  28.               if (type == 1)   {
  29.                   bank.addNewAccount(new CheckingAccount(s2.nextLine(), s2.nextDouble(), s2.nextDouble()));
  30.                   // read fields for Type 1 accounts and create new Type 1 object
  31.               }
  32.              else if (type ==2) {
  33.                   bank.addNewAccount(new SavingsAccount(s2.nextLine(), s2.nextDouble(), s2.nextDouble()));
  34.              }
  35.              else {
  36.                  bank.addNewAccount(new IRAAccount(s2.nextLine(), s2.nextDouble(), s2.nextDouble(), s2.nextInt(), s2.nextDouble()));
  37.              }
  38.              
  39.            // now go to top of loop, check infile to see if there is another line to read
  40.         }
  41.            
  42.         }
  43.  
  44.        
  45.         /*String csvFile = "customers.csv";
  46.         BufferedReader br = null;
  47.         String line = "";
  48.         String cvsSplitBy = ",";
  49.  
  50.         try {
  51.  
  52.             br = new BufferedReader(new FileReader(csvFile));
  53.             while ((line = br.readLine()) != null) {
  54.                
  55.                 //newAccount = BankDriver.createAccountFromSplitInputLine(line.split(","));
  56.  
  57.                
  58.                 String[] country = line.split(cvsSplitBy);
  59.                 System.out.println("Country [code= " + country[4] + " , name=" + country[5] + "]");
  60.  
  61.             }
  62.  
  63.         } catch (FileNotFoundException e) {
  64.             Account newAccount = null;
  65.         } catch (IOException e) {
  66.             e.printStackTrace();
  67.         }*/
  68.  
  69.        
  70.        
  71.         System.out.println("Creating accounts...");
  72.         //bank.addNewAccount(new SavingsAccount("Waterford Ellingsworth", 4350.0, 0.002));
  73.         //bank.addNewAccount(new CheckingAccount("Bethanie Treadwell", 500.0, 0.35));
  74.         //bank.addNewAccount(new IRAAccount("Ira Standish", 50000, 0.1, 59, 0.1));
  75.        
  76.         /* DebitCard is extra credit
  77.         try {
  78.             Class.forName("DebitCard");
  79.             //bank.addNewAccount(new DebitCard("Debi Cardashian", 5100, 0.0));
  80.            
  81.         } catch (ClassNotFoundException cnfe) {
  82.             // do nothing
  83.         }*/
  84.  
  85.         @SuppressWarnings("unchecked")
  86.         ArrayList<Account> list = bank.getAccounts();
  87.         printAccts(list, true);
  88.        
  89.         System.out.println("\nPerforming transactions...");
  90.         bank.getAccountByIndex(0).deposit(200.00);
  91.         bank.getAccountByIndex(1).withdraw(213.13);
  92.        
  93.         printAccts(list);
  94.  
  95.         System.out.println("\nUpdating accounts...");
  96.         for (Account a : list){
  97.             a.updateAccount();
  98.         }
  99.         printAccts(list, false);
  100.     }
  101.  
  102.     private static void printAccts(ArrayList<Account> list){
  103.         for (Account a : list){
  104.             System.out.println(a);
  105.         }
  106.     }
  107.     private static void printAccts(ArrayList<Account> list, boolean printHolder){
  108.         if (printHolder)
  109.             for (Account a : list){
  110.                 System.out.println("Customer: " + a.getHolder() + ", " + a);
  111.             }
  112.         else
  113.             printAccts(list);
  114.     }
  115. }
RAW Paste Data
Pastebin PRO BLACK FRIDAY Special!
Get 60% OFF on Pastebin PRO accounts!
Top