Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * File: BankDriver.java
- * Description: Demonstrates polymorphism and inheritance
- * Dependencies: Bank, Account, Transactions, CheckingAccount, SavingsAccount <, IRAAccount>
- *
- * @author Patty Kraft
- */
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class BankDriver {
- public static void main(String[] args) {
- Bank bank = new Bank();
- Scanner infile = new Scanner("customers.csv");
- while (infile.hasNextLine() ) {
- Scanner s2 = new Scanner(infile.nextLine()); // put string from file into second Scanner object
- s2.useDelimiter(",");
- if (s2.hasNextInt()) {
- int type = s2.nextInt();
- if (type == 1) {
- bank.addNewAccount(new CheckingAccount(s2.nextLine(), s2.nextDouble(), s2.nextDouble()));
- // read fields for Type 1 accounts and create new Type 1 object
- }
- else if (type ==2) {
- bank.addNewAccount(new SavingsAccount(s2.nextLine(), s2.nextDouble(), s2.nextDouble()));
- }
- else {
- bank.addNewAccount(new IRAAccount(s2.nextLine(), s2.nextDouble(), s2.nextDouble(), s2.nextInt(), s2.nextDouble()));
- }
- // now go to top of loop, check infile to see if there is another line to read
- }
- }
- /*String csvFile = "customers.csv";
- BufferedReader br = null;
- String line = "";
- String cvsSplitBy = ",";
- try {
- br = new BufferedReader(new FileReader(csvFile));
- while ((line = br.readLine()) != null) {
- //newAccount = BankDriver.createAccountFromSplitInputLine(line.split(","));
- String[] country = line.split(cvsSplitBy);
- System.out.println("Country [code= " + country[4] + " , name=" + country[5] + "]");
- }
- } catch (FileNotFoundException e) {
- Account newAccount = null;
- } catch (IOException e) {
- e.printStackTrace();
- }*/
- System.out.println("Creating accounts...");
- //bank.addNewAccount(new SavingsAccount("Waterford Ellingsworth", 4350.0, 0.002));
- //bank.addNewAccount(new CheckingAccount("Bethanie Treadwell", 500.0, 0.35));
- //bank.addNewAccount(new IRAAccount("Ira Standish", 50000, 0.1, 59, 0.1));
- /* DebitCard is extra credit
- try {
- Class.forName("DebitCard");
- //bank.addNewAccount(new DebitCard("Debi Cardashian", 5100, 0.0));
- } catch (ClassNotFoundException cnfe) {
- // do nothing
- }*/
- @SuppressWarnings("unchecked")
- ArrayList<Account> list = bank.getAccounts();
- printAccts(list, true);
- System.out.println("\nPerforming transactions...");
- bank.getAccountByIndex(0).deposit(200.00);
- bank.getAccountByIndex(1).withdraw(213.13);
- printAccts(list);
- System.out.println("\nUpdating accounts...");
- for (Account a : list){
- a.updateAccount();
- }
- printAccts(list, false);
- }
- private static void printAccts(ArrayList<Account> list){
- for (Account a : list){
- System.out.println(a);
- }
- }
- private static void printAccts(ArrayList<Account> list, boolean printHolder){
- if (printHolder)
- for (Account a : list){
- System.out.println("Customer: " + a.getHolder() + ", " + a);
- }
- else
- printAccts(list);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement