Account class The Account class will become an abstract cla

Account class

• The Account class will become an abstract class.
• The addTransactionInfo(String) method we become an abstract method.
• Each subclass will now hold its own implementation of the addTransactionInfo(String) method.
• You will have to adjust how the ArrayList<String> in Account is now accessed from the
subclasses. Think about best practices and encapsulation.


Reporter interface

This is an interface that will be implemented by the BankReport class. It will define the following
methods:

• void displayByCode(HashMap records, String prefix)
• void displayAllCodes(HashMap records)
• void displayInactiveCodes(HashMap records)


BankReport class

This is a new class that will implement the Reporter methods to display information about the Accounts
currently set up with the bank.

• displayByCode(HashMap records, String prefix) will take a reference to the HashMap that
contains all the Accounts in the bank and the prefix code that we used to identify each Account
subtype. eg call. displayByCode(theBank, \"gl\") Only the account numbers that hold the prefix
code specified will be displayed.
• displayAllCodes(HashMap records) will display all the active Accounts in the bank. The output
will be displayed sorted by account number.
• displayInactiveCodes(HashMap records) will display only the inactive accounts in the bank,
sorted by account number descending.
• Another method, public void displayAccountTotals(HashMap theBank) will display a formatted
dollar value which is the sum of all account balances in the bank.


ATM class

• ATM will now feature a submenu for Bank Employees.
• If a user logs in as a bank employee they will be presented with a menu that will allow them to
access the report functions described above.
• The bank employee menu will list the options 1 to 4 to match the report functions stated above.
• Bank employees will not be allowed to alter account information
• Bank employee login will be \"admin\" and \"admin\" for both username and password
• There is no need for a separate class to support bank employees. All that is required is to check
the login info provided and direct that user to the employee menu where appropriate.

Modify the classes bellow to match the information above:

import java.util.ArrayList;
import java.util.Date;

/**
* Account super class
*
* @author Bullwinkle Moose
* @version 1.0
*/
public class Account {
   private double balance;
   private String accountNumber;
   private boolean active;
   private ArrayList<String> accountRecords;

   /**
   * Default constructor
   */
   public Account() {
   }

   /**
   * Overloaded constructor
   *
   * @param balance
   * the balance to set
   * @param accountNumber
   * the account number to set
   *
   */
   public Account(double balance, String accountNumber) {
       setBalance(balance);
       setAccountNumber(accountNumber);
       active = true;
       accountRecords = new ArrayList<String>();
   }

   /**
   *
   * @return the balance as double
   */
   public double getBalance() {

       return balance;
   }

   /**
   *
   * @param balance
   * the balance to set
   */
   public void setBalance(double balance) {

       if (balance >= 0) {
           this.balance = balance;
       }
   }

   /**
   *
   * @return the accountNumber as String
   */
   public String getAccountNumber() {

       return accountNumber;
   }

   /**
   *
   * @param accountNumber
   * the accountNumber to set
   */
   public void setAccountNumber(String accountNumber) {

       if (accountNumber != null && !accountNumber.isEmpty()) {
           this.accountNumber = accountNumber;
       }
   }

   /**
   *
   * @return the active as boolean
   */
   public boolean isActive() {

       return active;
   }

   /**
   *
   * @param active
   * the active to set
   */
   public void setActive(boolean active) {

       this.active = active;
   }

   /**
   *
   * @param transactionInfo
   * the information to add to ArrayList
   */
   public void addTransaction(String transactionInfo) {

       if (accountNumber != null && !accountNumber.isEmpty()) {
           accountRecords.add(transactionInfo);
          
       }
   }

   /**
   * Displays the transaction information.
   */
   public void displayAccountRecords() {

       System.out.println(\"Acount Activity: \");

       for (String info : accountRecords) {
           System.out.println(info);
       }

   }

   /**
   *
   * @param amount
   * the amount to add to the existing field
   */
   public void addToBalance(double amount) {

       if (amount > 0.0) {
           balance += amount;
           addTransaction(String.format(\"%s - deposit: $%.2f\", new Date(), amount));
       }
   }

   /**
   *
   * @param amount
   * the amount to subtract from the balance
   */
   public void subtractFromBalance(double amount) {

       if (amount > 0.0) {
           balance -= amount;
           addTransaction(String.format(\"%s - withdrawal: $%.2f\", new Date(), amount));
       }
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return \"Account [balance=\" + balance + \", accountNumber=\"
               + accountNumber + \", active=\" + active + \"]\";
   }

}


------------------------------------


/**
* ATM class, The COMP 1451 Assignment application driver
*/

/**
* @author Bullwinkle Moose
* @version 2.0
*
*/
public class ATM {
   private InputReader reader;
   private String accountNumber;
   private String passcode;
   private boolean customerVerified;

   private Bank theBank;
   private BankCustomer currentCustomer;
   private Account currentAccount;

   private final int GOLD_AGE = 65;

   /**
   * Default constructor. Calls the initialize() method to seed the Bank with
   * some BankCustomers. Calls the run() method to perform the primary program
   * functions.
   */
   public ATM() {
       theBank = new Bank();
       initialize();
       run();
   }

   /**
   * Main method calls the class default constructor.
   *
   * @param args
   * for program arguments (not used)
   */
   public static void main(String[] args) {
       new ATM();

   }

   /**
   * The primary application processor. All application functions are called
   * from here. Starts by seeding the Bank class HashMap with BankCustomers,
   * and display a menu of choices. Uses a loop to prompt users to perform
   * banking transactions. Must use switch/case selection to determine uses
   * choices.
   */
   public void run() {

       reader = new InputReader();
       boolean exit = false;

       System.out.println(\"Welcome to Bullwinkle\'s Bank.\");

       while (!exit) {
           System.out.println(\"\");
           System.out.println(\"Choose one of the following options:\");
           System.out.println(\"1 - Sign In\");
           System.out.println(\"2 - Deposit\");
           System.out.println(\"3 - Withdraw\");
           System.out.println(\"4 - Display Account Info\");
           System.out.println(\"5 - Exit\");
           System.out.print(\"> \");
           int choice = reader.getIntInput();

           switch (choice) {
           case 1:
               verifyCustomer();
               break;
           case 2:
               transactDeposit();
               break;
           case 3:
               transactWithdraw();
               break;
           case 4:
               displayAccountInformation();
               break;
           case 5:
               shutDown();
           default:
               System.out.println(\"KA-BOOM!!!\");
               System.exit(0);
           }
       }
   }

   /**
   * Adds Customer references to the Bank HashMap as seed data for testing.
   */
   public void initialize() {

       BankCustomer[] customers = { new BankCustomer(\"Darby\", \"Dog\", \"123\", 35),
               new BankCustomer(\"Myia\", \"Dog\", \"456\", 12), new BankCustomer(\"Freckle\", \"Cat\", \"789\", 65) };

       Account[] accounts = { new SavingsAccount(100.0, \"SA-123\"), new ChequingAccount(50.0, \"CH-123\"),
               new GoldAccount(200.0, \"GL-123\") };

       for (int i = 0; i < customers.length; i++) {

           if (accounts[i] instanceof GoldAccount && customers[i].getAge() < GOLD_AGE) {

               customers[i].setAccount(new SavingsAccount(0.0, \"SA-DEFAULT\"));
               System.out.println(\"ERROR: Customer is too young to have a GoldAccount.\ \"
                       + \"Savings Account created instead. Try again after your next birthday.\");

           } else {
               customers[i].setAccount(accounts[i]);
           }

       }

       for (BankCustomer customer : customers) {
           theBank.createAccount(customer);
       }

   }

   /**
   * Performs a deposit into a BankCustomer\'s account. Checks to see if the
   * user has signed in. If not, then verifyCustomer() is called and the menu
   * is displayed again.
   */
   public void transactDeposit() {

       if (customerVerified) {
           System.out.println(\"Enter the amount to deposit: \");
           double amount = reader.getDoubleInput();
           currentCustomer.getAccount().addToBalance(amount);
          

       } else {

           System.out.println(\"ERROR: You must LOGIN before you can perform a transaction.\");
           verifyCustomer();
       }
   }

   /**
   * Performs a withdrawal from a BankCustomer\'s account. Checks to see if the
   * user has signed in. If not, then verifyCustomer() is called and the menu
   * is displayed again.
   */
   public void transactWithdraw() {

       if (customerVerified) {
           System.out.println(\"Enter the amount to withdraw: \");
           double amount = reader.getDoubleInput();

           currentCustomer.getAccount().subtractFromBalance(amount);
      
       } else {

           System.out.println(\"ERROR: You must LOGIN before you can perform a transaction.\");
           verifyCustomer();
       }

   }

   /**
   * Performs a withdrawal from a BankCustomer\'s account. Checks to see if the
   * user has signed in. If not, then verifyCustomer() is called and the menu
   * is displayed again.
   */
   public void displayAccountInformation() {

       if (customerVerified) {
           System.out.println(\"Here is your information.\");
           Bank.displayCustomerInformation(currentCustomer);
       } else {

           System.out.println(\"ERROR: You must LOGIN before you can perform a transaction.\");
           verifyCustomer();
       }

   }

   /**
   * To confirm a BankCustomer\'s account number and passcode. Called when the
   * user is required to sign in to the application. Will set a boolean so the
   * user does not have to sign in again during the session.
   */
   public void verifyCustomer() {

       System.out.println(\"Enter Account Number: \");
       accountNumber = reader.getStringInput();
       System.out.println(\"Enter Passcode: \");
       passcode = reader.getStringInput();

       currentCustomer = Bank.theBank.get(accountNumber);
       currentAccount = currentCustomer.getAccount();

       if (currentCustomer != null) {
           if (passcode.equals(currentCustomer.getPasscode())) {

               customerVerified = true;
           } else {
               System.out.println(\"ERROR: Either account number or passcode is not correct.\");
               run();
           }

       } else {
           System.out.println(\"ERROR: Either account number or passcode is not correct.\");
           run();
       }

   }

   /**
   * Displays the final information for the current account along with the
   * account transaction history. Then displays all the account data for all
   * bank customer and terminates the program run.
   */
   public void shutDown() {

       System.out.println(\"Thank you for banking at Bullwinkle\'s Bank\");

       System.out.println(\"ACCOUNT SUMMARY:\");
       Bank.displayCustomerInformation(currentCustomer);
       currentAccount.displayAccountRecords();

       System.out.println(\"\");

       System.out.println(\"Displaying all the accounts in the bank.\");
       Bank.displayAllCustomers();
       System.exit(0);
   }
}


------------------------------------


import java.util.HashMap;

/**
* Bank class.
* Supports a HashMap of customer accounts.
*/

/**
* @author Bullwinkle Moose
* @version 2.0
*/
public class Bank {

   public static HashMap<String, BankCustomer> theBank;

   /**
   * Default constructor for Bank class. Initializes the HashMap
   */
   public Bank() {
       super();
       theBank = new HashMap<String, BankCustomer>();
   }

   /**
   * Add a new BankCustomer element to the HashMap.
   *
   * @param newCustomer
   * The new element to add to the HashpMap using the account
   * number as the key and the new BankCustomer as the value.
   */
   public void createAccount(BankCustomer newCustomer) {

       if (newCustomer != null) {
           theBank.put(newCustomer.getAccount().getAccountNumber(),
                   newCustomer);
       }
   }

   /**
   * Deactivates a customer\'s account
   *
   * @param accountNumber
   * the account to be deactivated
   *
   */
   public void deactivate(String accountNumber) {

       if (accountNumber != null && !accountNumber.isEmpty()) {

           theBank.get(accountNumber).getAccount().setActive(false);

       }
   }

   /**
   * Gets the BankCustomer from the HashMap and adds a double amount to a
   * BankCustomer\'s balance.
   *
   * @param accountNumber
   * The account number of the BankCustomer.
   * @param amount
   * The amount to deposit.
   */
   public void deposit(String accountNumber, double amount) {

       if (accountNumber != null && amount > 0.0) {

           theBank.get(accountNumber).getAccount().addToBalance(amount);

       }
   }

   /**
   * Gets the BankCustomer from the HashMap and subtracts an amount from a
   * BankCustomer\'s balance as long as it does not leave a negative balance.
   *
   * @param accountNumber
   * The account number of the BankCustomer.
   * @param amount
   * The amount to subtract from a BankCustomer\'s balance.
   */
   public void withdraw(String accountNumber, double amount) {

       if (accountNumber != null && !accountNumber.isEmpty()) {

           if (amount != 0.0) {

               theBank.get(accountNumber).getAccount()
                       .subtractFromBalance(amount);
           }
       }

   }

   /**
   * Displays the details of a BankCustomer element in the HshMap. Uses
   * BankCustomer.toString() implementation.
   *
   * @param customer
   * the BankCustomer chosen to display.
   */
   public static void displayCustomerInformation(BankCustomer customer) {

       if (customer != null) {

           System.out.println(customer);
       }
   }

   /**
   * Displays all elements of the HashMap by using BankCustomer.toString()
   * implementation of each.
   */
   public static void displayAllCustomers() {

       for (BankCustomer customer : theBank.values()) {

           System.out.println(customer);

       }
   }

}


--------------------------------------


/**
* BankCustomer data class to hold customer information.
*
* @author Bullwinkle Moose
* @version 2.0
*/
public class BankCustomer {
   private String firstName;
   private String lastName;
   private String passcode;
   private Account account;
   private int age;

   /**
   * Default constructor for a BankCustomer. Sets the fields to the default
   * values for each type.
   */
   public BankCustomer() {
       super();
   }

   /**
   * Overloaded constructor to initialize objects of the BankCustomer class.
   *
   * @param firstName
   * the first name of the customer
   * @param lastName
   * the last name of the customer
   * @param passcode
   * the passcode of the customer
   * @param age
   * the age of the customer
   */
   public BankCustomer(String firstName, String lastName, String passcode,
           int age) {
       super();
       setFirstName(firstName);
       setLastName(lastName);
       setPasscode(passcode);
       setAge(age);
       account = new Account();
   }

   /**
   * Returns the first name of the bank customer.
   *
   * @return the firstName as String
   */
   public String getFirstName() {

       return firstName;
   }

   /**
   * Sets the first name of the bank customer.
   *
   * @param firstName
   * the firstName to set
   */
   public void setFirstName(String firstName) {

       if (firstName != null && !firstName.isEmpty()) {
           this.firstName = firstName;
       }
   }

   /**
   * Returns the last name of the bank customer.
   *
   * @return the lastName as String
   */
   public String getLastName() {

       return lastName;
   }

   /**
   * Sets the last name of the bank customer.
   *
   * @param lastName
   * the lastName to set
   */
   public void setLastName(String lastName) {

       if (lastName != null && !lastName.isEmpty()) {
           this.lastName = lastName;
       }
   }

   /**
   * Returns the passcode of the bank customer.
   *
   * @return the passcode as String
   */
   public String getPasscode() {

       return passcode;
   }

   /**
   * Sets the passcode of the bank customer.
   *
   * @param passcode
   * the passcode to set
   */
   public void setPasscode(String passcode) {

       if (passcode != null && !passcode.isEmpty()) {
           this.passcode = passcode;
       }
   }

   /**
   * Returns the customer account.
   *
   * @return the myAccount as Account
   */
   public Account getAccount() {

       return account;
   }

   /**
   * Sets the customer account.
   *
   * @param myAccount
   * the myAccount to set
   */
   public void setAccount(Account account) {

       if (account != null) {
           this.account = account;
       }
   }

   /**
   * Returns the age of the customer.
   *
   * @return the age as int
   */
   public int getAge() {

       return age;
   }

   /**
   * Sets the age of the customer.
   *
   * @param age
   * the age to set
   */
   public void setAge(int age) {

       if (age >= 0) {
           this.age = age;
       }
   }

   /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return \"BankCustomer [firstName=\" + firstName + \", lastName=\"
               + lastName + \", passcode=\" + passcode + \", account=\" + account
               + \", age=\" + age + \"]\";
   }

  

}


-------------------------------------------


/**
* ChequingAccount data class
*
* @author Bullwinkle Moose
* @version 1.0
*/
public class ChequingAccount extends Account {
  
   public static final double FEE = 0.25;
   private static final double MIN_AMOUNT = 0.0;
   private int numberOfCheques;
   private double totalFees;

   /**
   * Default constructor
   */
   public ChequingAccount() {
       super();
   }

   /**
   * Overloaded constructor
   *
   * @param balance
   * the balance to set
   * @param accountNumber
   * the account number to set
   *
   */
   public ChequingAccount(double balance, String accountNumber) {

       super(balance, accountNumber);
       numberOfCheques = 0;
   }

   /**
   *
   * @return the numberOfCheques as int
   */
   public int getNumberOfCheques() {

       return numberOfCheques;
   }

   /**
   *
   * @param numberOfCheques
   * the numberOfCheques to set
   */
   public void setNumberOfCheques(int numberOfCheques) {

       if (numberOfCheques > 0) {
           this.numberOfCheques = numberOfCheques;
       }
   }
  
   /**
   * Adds 1 to the number of cheques whenever there is a withdrawal
   * from a ChequingAccount
   */
   public void addACheque(){
      
       numberOfCheques ++;
   }
  
  
   /*
   * (non-Javadoc)
   *
   * @see Account#subtractFromBalance(double)
   */
   @Override
   public void subtractFromBalance(double amount) {

       if (getBalance() - amount >= MIN_AMOUNT) {
          
           super.subtractFromBalance(amount);  
           addACheque();
           totalFees = numberOfCheques * FEE;

       }
   }

   /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return \"ChequingAccount [numberOfCheques=\" + numberOfCheques + \", totalFees=\" + totalFees + \", toString()=\"
               + super.toString() + \"]\";
   }

  

}


----------------------------------------


/**
* GoldAccount data class
*
* @author Bullwinkle Moose
* @version 1.0
*/
public class GoldAccount extends Account {

   private boolean overdraft;

   public static final double INTEREST_RATE = 0.025;
   public static final double FEE = 10.0;
   public static final double OVERDRAFT_AMT = -5000.0;

   /**
   * Default constructor
   */
   public GoldAccount() {
       super();
   }

   /**
   * Overloaded constructor
   *
   * @param balance
   * the balance to set
   * @param accountNumber
   * the account number to set
   *
   */
   public GoldAccount(double balance, String accountNumber) {
       super(balance, accountNumber);
       overdraft = false;
   }

   /**
   *
   * @return the interestRate as double
   */
   public double getInterestRate() {

       return INTEREST_RATE;
   }

   /**
   *
   * @return the inOverdraft as boolean
   */
   public boolean isOverdraft() {

       return overdraft;
   }

   /**
   *
   * @param inOverdraft
   * the inOverdraft to set
   */
   public void setOverdraft(boolean overdraft) {

       this.overdraft = overdraft;
   }

   /*
   * (non-Javadoc)
   *
   * @see Account#subtractFromBalance(double)
   */
   @Override
   public void subtractFromBalance(double amount) {

       if (getBalance() - amount >= GoldAccount.OVERDRAFT_AMT) {
          
           super.subtractFromBalance(amount);  

       }
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return \"GoldAccount [interestRate=\" + INTEREST_RATE + \", overdraft=\" + overdraft + \", toString()=\"
               + super.toString() + \"]\";
   }

}


--------------------------------


/**
* SavingsAccount data class
*
* @author Bullwinkle Moose
* @version 1.0
*/
public class SavingsAccount extends Account {
  
   public static final double MIN_AMOUNT = 100.0;

   /**
   * Default constructor
   */
   public SavingsAccount() {
       super();
   }

   /**
   * Overloaded constructor
   *
   * @param balance
   * the balance to set
   * @param accountNumber
   * the account number to set
   */
   public SavingsAccount(double balance, String accountNumber) {
       super(balance, accountNumber);
   }
      

   /**
   * @return the minAmount constant as a double
   */
   public static double getMinAmount() {
       return MIN_AMOUNT;
   }
  
   /*
   * (non-Javadoc)
   *
   * @see Account#subtractFromBalance(double)
   */
   @Override
   public void subtractFromBalance(double amount) {

       if (getBalance() - amount >= MIN_AMOUNT) {
          
           super.subtractFromBalance(amount);  

       }
   }

   /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return \"SavingsAccount [toString()=\" + super.toString() + \"]\";
   }

  
}


--------------------------------------

import java.util.Scanner;

/**
* Class InputReader reads user input from the keyboard.
*/

/**
* @version 2016.01.20
* @author Bullwinkle Moose
*/
public class InputReader {
private Scanner scanner;

/**
* Default constructor for InputReader class Create a new InputReader to
* read user input.
*/
public InputReader() {
scanner = new Scanner(System.in);
}

/**
* Retrieves a user\'s int input
*
* @return the user\'s input as an int
*/
public int getIntInput() {
try {
return scanner.nextInt();
} catch (java.util.InputMismatchException e) {
System.out.println(\"Not a number - treating as zero\");
scanner.nextLine(); // clear the buffer
return 0;
}
}

/**
* Retrieves a user\'s double input
*
* @return the user\'s input as a double
*/
public double getDoubleInput() {
try {
return scanner.nextDouble();
} catch (java.util.InputMismatchException e) {
System.out.println(\"Not a number - treating as zero\");
scanner.nextLine(); // clear the buffer
return 0.0;
}
}

/**
* Retrieves a user\'s String input
*
* @return the user\'s input as a String
*/
public String getStringInput() {

String input = scanner.next();
if (input.length() > 0) {
return input;
} else {
System.out.println(\"ERROR:Invalid input provided\");
}
return null;

}
}

Solution

PROGRAM CODE:

Account.java

package Sample;

import java.util.ArrayList;
import java.util.Date;
/**
* Account super class
*
* @author Bullwinkle Moose
* @version 1.0
*/
public abstract class Account {
private double balance;
private String accountNumber;
private boolean active;
private ArrayList<String> accountRecords;
/**
* Default constructor
*/
public Account() {
}
/**
* Overloaded constructor
*
* @param balance
* the balance to set
* @param accountNumber
* the account number to set
*
*/
public Account(double balance, String accountNumber) {
setBalance(balance);
setAccountNumber(accountNumber);
active = true;
accountRecords = new ArrayList<String>();
}
/**
*
* @return the balance as double
*/
public double getBalance() {
return balance;
}
/**
*
* @param balance
* the balance to set
*/
public void setBalance(double balance) {
if (balance >= 0) {
this.balance = balance;
}
}
/**
*
* @return the accountNumber as String
*/
public String getAccountNumber() {
return accountNumber;
}
/**
*
* @param accountNumber
* the accountNumber to set
*/
public void setAccountNumber(String accountNumber) {
if (accountNumber != null && !accountNumber.isEmpty()) {
this.accountNumber = accountNumber;
}
}
/**
*
* @return the active as boolean
*/
public boolean isActive() {
return active;
}
/**
*
* @param active
* the active to set
*/
public void setActive(boolean active) {
this.active = active;
}
/**
*
* @param transactionInfo
* the information to add to ArrayList
*/
public void addTransaction(String transactionInfo) {
accountRecords.add(transactionInfo);
  
}
  
/**
*
* @param transactionInfo
* the information to add to ArrayList
*/
public abstract void addTransactionInfo(String transactionInfo);
/**
* Displays the transaction information.
*/
public void displayAccountRecords() {
System.out.println(\"Acount Activity: \");
for (String info : accountRecords) {
System.out.println(info);
}
}
/**
*
* @param amount
* the amount to add to the existing field
*/
public void addToBalance(double amount) {
if (amount > 0.0) {
balance += amount;
addTransaction(String.format(\"%s - deposit: $%.2f\", new Date(), amount));
}
}
/**
*
* @param amount
* the amount to subtract from the balance
*/
public void subtractFromBalance(double amount) {
if (amount > 0.0) {
balance -= amount;
addTransaction(String.format(\"%s - withdrawal: $%.2f\", new Date(), amount));
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return \"Account [balance=\" + balance + \", accountNumber=\"
+ accountNumber + \", active=\" + active + \"]\";
}
}

ATM.java

package Account;

/**

* ATM class, The COMP 1451 Assignment application driver

*/

/**

* @author Bullwinkle Moose

* @version 2.0

*

*/

public class ATM {

private InputReader reader;

private String accountNumber;

private String passcode;

private boolean customerVerified;

private Bank theBank;

private BankCustomer currentCustomer;

private Account currentAccount;

private final int GOLD_AGE = 65;

private BankReport report;

/**

* Default constructor. Calls the initialize() method to seed the Bank with

* some BankCustomers. Calls the run() method to perform the primary program

* functions.

*/

public ATM() {

theBank = new Bank();

initialize();

run();

}

/**

* Main method calls the class default constructor.

*

* @param args

* for program arguments (not used)

*/

public static void main(String[] args) {

new ATM();

}

/**

* The primary application processor. All application functions are called

* from here. Starts by seeding the Bank class HashMap with BankCustomers,

* and display a menu of choices. Uses a loop to prompt users to perform

* banking transactions. Must use switch/case selection to determine uses

* choices.

*/

public void run() {

reader = new InputReader();

boolean exit = false;

System.out.println(\"Welcome to Bullwinkle\'s Bank.\");

while (!exit) {

System.out.println(\"\");

System.out.println(\"Choose one of the following options:\");

System.out.println(\"1 - Sign In\");

System.out.println(\"2 - Deposit\");

System.out.println(\"3 - Withdraw\");

System.out.println(\"4 - Display Account Info\");

System.out.println(\"5 - Exit\");

System.out.print(\"> \");

int choice = reader.getIntInput();

switch (choice) {

case 1:

verifyCustomer();

break;

case 2:

transactDeposit();

break;

case 3:

transactWithdraw();

break;

case 4:

displayAccountInformation();

break;

case 5:

   if(currentCustomer != null)

       shutDown(true);

   else

       shutDown(false);

default:

System.out.println(\"KA-BOOM!!!\");

System.exit(0);

}

}

}

/**

* Adds Customer references to the Bank HashMap as seed data for testing.

*/

public void initialize() {

BankCustomer[] customers = { new BankCustomer(\"Darby\", \"Dog\", \"123\", 35),

new BankCustomer(\"Myia\", \"Dog\", \"456\", 12), new BankCustomer(\"Freckle\", \"Cat\", \"789\", 65) };

Account[] accounts = { new SavingsAccount(100.0, \"SA-123\"), new ChequingAccount(50.0, \"CH-123\"),

new GoldAccount(200.0, \"GL-123\") };

for (int i = 0; i < customers.length; i++) {

if (accounts[i] instanceof GoldAccount && customers[i].getAge() < GOLD_AGE) {

customers[i].setAccount(new SavingsAccount(0.0, \"SA-DEFAULT\"));

System.out.println(\"ERROR: Customer is too young to have a GoldAccount.\ \"

+ \"Savings Account created instead. Try again after your next birthday.\");

} else {

customers[i].setAccount(accounts[i]);

}

}

for (BankCustomer customer : customers) {

theBank.createAccount(customer);

}

}

/**

* Performs a deposit into a BankCustomer\'s account. Checks to see if the

* user has signed in. If not, then verifyCustomer() is called and the menu

* is displayed again.

*/

public void transactDeposit() {

if (customerVerified) {

System.out.println(\"Enter the amount to deposit: \");

double amount = reader.getDoubleInput();

currentCustomer.getAccount().addToBalance(amount);

  

} else {

System.out.println(\"ERROR: You must LOGIN before you can perform a transaction.\");

verifyCustomer();

}

}

/**

* Performs a withdrawal from a BankCustomer\'s account. Checks to see if the

* user has signed in. If not, then verifyCustomer() is called and the menu

* is displayed again.

*/

public void transactWithdraw() {

if (customerVerified) {

System.out.println(\"Enter the amount to withdraw: \");

double amount = reader.getDoubleInput();

currentCustomer.getAccount().subtractFromBalance(amount);

  

} else {

System.out.println(\"ERROR: You must LOGIN before you can perform a transaction.\");

verifyCustomer();

}

}

/**

* Performs a withdrawal from a BankCustomer\'s account. Checks to see if the

* user has signed in. If not, then verifyCustomer() is called and the menu

* is displayed again.

*/

public void displayAccountInformation() {

if (customerVerified) {

System.out.println(\"Here is your information.\");

Bank.displayCustomerInformation(currentCustomer);

} else {

System.out.println(\"ERROR: You must LOGIN before you can perform a transaction.\");

verifyCustomer();

}

}

/**

* To confirm a BankCustomer\'s account number and passcode. Called when the

* user is required to sign in to the application. Will set a boolean so the

* user does not have to sign in again during the session.

*/

public void verifyCustomer() {

System.out.println(\"Enter Account Number: \");

accountNumber = reader.getStringInput();

System.out.println(\"Enter Passcode: \");

passcode = reader.getStringInput();

if(accountNumber.equals(\"admin\") && passcode.equals(\"admin\"))

{

   runEmployee();

}

else

{

   currentCustomer = Bank.theBank.get(accountNumber);

   currentAccount = currentCustomer.getAccount();

   if (currentCustomer != null) {

   if (passcode.equals(currentCustomer.getPasscode())) {

   customerVerified = true;

   } else {

   System.out.println(\"ERROR: Either account number or passcode is not correct.\");

   run();

   }

   } else {

   System.out.println(\"ERROR: Either account number or passcode is not correct.\");

   run();

   }

}

}

  

public void runEmployee() {

   report = new BankReport();

reader = new InputReader();

boolean exit = false;

System.out.println(\"Welcome to Bullwinkle\'s Bank.\");

while (!exit) {

System.out.println(\"\");

System.out.println(\"Choose one of the following options:\");

System.out.println(\"1 - Display Accounts by Code\");

System.out.println(\"2 - Display All Codes\");

System.out.println(\"3 - Display Inactive Codes\");

System.out.println(\"4 - Display Account Totals\");

System.out.println(\"5 - Exit\");

System.out.print(\"> \");

int choice = reader.getIntInput();

switch (choice) {

case 1:

   System.out.println(\"Enter the code: \");

   String code = reader.getStringInput();

report.displayByCode(Bank.theBank, code);

break;

case 2:

   report.displayAllCodes(Bank.theBank);

break;

case 3:

report.displayInactiveCodes(Bank.theBank);

break;

case 4:

report.displayAccountTotals(Bank.theBank);

break;

case 5:

shutDown(false);

default:

System.out.println(\"KA-BOOM!!!\");

System.exit(0);

}

}

}

/**

* Displays the final information for the current account along with the

* account transaction history. Then displays all the account data for all

* bank customer and terminates the program run.

*/

public void shutDown(boolean isCustomer) {

System.out.println(\"Thank you for banking at Bullwinkle\'s Bank\");

if(isCustomer)

{

   System.out.println(\"ACCOUNT SUMMARY:\");

   Bank.displayCustomerInformation(currentCustomer);

   currentAccount.displayAccountRecords();

}

System.out.println(\"\");

System.out.println(\"Displaying all the accounts in the bank.\");

Bank.displayAllCustomers();

System.exit(0);

}

}

BankCustomer.java

package Sample;

/**
* BankCustomer data class to hold customer information.
*
* @author Bullwinkle Moose
* @version 2.0
*/
public class BankCustomer {
private String firstName;
private String lastName;
private String passcode;
private Account account;
private int age;
/**
* Default constructor for a BankCustomer. Sets the fields to the default
* values for each type.
*/
public BankCustomer() {
super();
}
/**
* Overloaded constructor to initialize objects of the BankCustomer class.
*
* @param firstName
* the first name of the customer
* @param lastName
* the last name of the customer
* @param passcode
* the passcode of the customer
* @param age
* the age of the customer
*/
public BankCustomer(String firstName, String lastName, String passcode,
int age) {
super();
setFirstName(firstName);
setLastName(lastName);
setPasscode(passcode);
setAge(age);
//account = new Account();
}
/**
* Returns the first name of the bank customer.
*
* @return the firstName as String
*/
public String getFirstName() {
return firstName;
}
/**
* Sets the first name of the bank customer.
*
* @param firstName
* the firstName to set
*/
public void setFirstName(String firstName) {
if (firstName != null && !firstName.isEmpty()) {
this.firstName = firstName;
}
}
/**
* Returns the last name of the bank customer.
*
* @return the lastName as String
*/
public String getLastName() {
return lastName;
}
/**
* Sets the last name of the bank customer.
*
* @param lastName
* the lastName to set
*/
public void setLastName(String lastName) {
if (lastName != null && !lastName.isEmpty()) {
this.lastName = lastName;
}
}
/**
* Returns the passcode of the bank customer.
*
* @return the passcode as String
*/
public String getPasscode() {
return passcode;
}
/**
* Sets the passcode of the bank customer.
*
* @param passcode
* the passcode to set
*/
public void setPasscode(String passcode) {
if (passcode != null && !passcode.isEmpty()) {
this.passcode = passcode;
}
}
/**
* Returns the customer account.
*
* @return the myAccount as Account
*/
public Account getAccount() {
return account;
}
/**
* Sets the customer account.
*
* @param myAccount
* the myAccount to set
*/
public void setAccount(Account account) {
if (account != null) {
this.account = account;
}
}
/**
* Returns the age of the customer.
*
* @return the age as int
*/
public int getAge() {
return age;
}
/**
* Sets the age of the customer.
*
* @param age
* the age to set
*/
public void setAge(int age) {
if (age >= 0) {
this.age = age;
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return \"BankCustomer [firstName=\" + firstName + \", lastName=\"
+ lastName + \", passcode=\" + passcode + \", account=\" + account
+ \", age=\" + age + \"]\";
}
  
}

BankReport.java

package Sample;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class BankReport implements Reporter{

   //Consider the key to the hashmap as the account number since account numbers are unique
   @Override
   public void displayByCode(HashMap<String, BankCustomer> records, String prefix) {
       Set<String> accountNumbers = records.keySet();
      
       Iterator<String> itr = accountNumbers.iterator();
       while(itr.hasNext())
       {
           String number = itr.next();
           if(number.contains(prefix.toUpperCase()) || number.contains(prefix.toLowerCase()))  
           {
               System.out.println(number);
           }
       }
   }

   @Override
   public void displayAllCodes(HashMap<String, BankCustomer> records) {
       Set<String> accountNumbers = records.keySet();
      
       Iterator<String> itr = accountNumbers.iterator();
       while(itr.hasNext())
       {
           String number = itr.next();
           System.out.println(number);
       }
   }

   @Override
   public void displayInactiveCodes(HashMap<String, BankCustomer> records) {
       HashMap<String, Integer> inactiveAccount = new HashMap<String, Integer>();
       Set<String> accountNumbers = records.keySet();
      
       Iterator<String> itr = accountNumbers.iterator();
       while(itr.hasNext())
       {
           BankCustomer customer = records.get(itr.next());
           Account account = customer.getAccount();
           if(!account.isActive())
           {
               String accountNumber = account.getAccountNumber();
               inactiveAccount.put(accountNumber, Integer.valueOf(accountNumber.substring(3,accountNumber.length())));
           }
       }
       Set<Entry<String, Integer>> set = inactiveAccount.entrySet();
List<Entry<String, Integer>> list = new ArrayList<Entry<String, Integer>>(set);
       Collections.sort( list, new Comparator<Map.Entry<String, Integer>>()
       {
       public int compare( Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2 )
       {
       return (o2.getValue()).compareTo( o1.getValue() );
       }
       } );
      
      
       for(Map.Entry<String, Integer> entry:list){
System.out.println(entry.getValue());
}
   }

   void displayAccountTotals(HashMap<String, BankCustomer> theBank)
   {
       Set<String> accountNumbers = theBank.keySet();
       double total = 0;
       Iterator<String> itr = accountNumbers.iterator();
       while(itr.hasNext())
       {
           String number = itr.next();
           BankCustomer customer = theBank.get(number);
           Account acc = customer.getAccount();
           total += acc.getBalance();
       }
       System.out.println(\"Total: \" + total);
   }

}

ChequingAccount.java

package Sample;

/**
* ChequingAccount data class
*
* @author Bullwinkle Moose
* @version 1.0
*/
public class ChequingAccount extends Account {
  
public static final double FEE = 0.25;
private static final double MIN_AMOUNT = 0.0;
private int numberOfCheques;
private double totalFees;
/**
* Default constructor
*/
public ChequingAccount() {
super();
}
/**
* Overloaded constructor
*
* @param balance
* the balance to set
* @param accountNumber
* the account number to set
*
*/
public ChequingAccount(double balance, String accountNumber) {
super(balance, accountNumber);
numberOfCheques = 0;
}
/**
*
* @return the numberOfCheques as int
*/
public int getNumberOfCheques() {
return numberOfCheques;
}
/**
*
* @param numberOfCheques
* the numberOfCheques to set
*/
public void setNumberOfCheques(int numberOfCheques) {
if (numberOfCheques > 0) {
this.numberOfCheques = numberOfCheques;
}
}
  
/**
* Adds 1 to the number of cheques whenever there is a withdrawal
* from a ChequingAccount
*/
public void addACheque(){
  
numberOfCheques ++;
}
  
  
/*
* (non-Javadoc)
*
* @see Account#subtractFromBalance(double)
*/
@Override
public void subtractFromBalance(double amount) {
if (getBalance() - amount >= MIN_AMOUNT) {
  
super.subtractFromBalance(amount);
addACheque();
totalFees = numberOfCheques * FEE;
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return \"ChequingAccount [numberOfCheques=\" + numberOfCheques + \", totalFees=\" + totalFees + \", toString()=\"
+ super.toString() + \"]\";
}
   @Override
   public void addTransactionInfo(String transactionInfo) {
       String accountNumber = getAccountNumber();
       if (accountNumber != null && !accountNumber.isEmpty()) {
addTransaction(transactionInfo);
  
}
   }
  
  
}

GoldAccount.java

package Sample;

/**
* GoldAccount data class
*
* @author Bullwinkle Moose
* @version 1.0
*/
public class GoldAccount extends Account {
private boolean overdraft;
public static final double INTEREST_RATE = 0.025;
public static final double FEE = 10.0;
public static final double OVERDRAFT_AMT = -5000.0;
/**
* Default constructor
*/
public GoldAccount() {
super();
}
/**
* Overloaded constructor
*
* @param balance
* the balance to set
* @param accountNumber
* the account number to set
*
*/
public GoldAccount(double balance, String accountNumber) {
super(balance, accountNumber);
overdraft = false;
}
/**
*
* @return the interestRate as double
*/
public double getInterestRate() {
return INTEREST_RATE;
}
/**
*
* @return the inOverdraft as boolean
*/
public boolean isOverdraft() {
return overdraft;
}
/**
*
* @param inOverdraft
* the inOverdraft to set
*/
public void setOverdraft(boolean overdraft) {
this.overdraft = overdraft;
}
/*
* (non-Javadoc)
*
* @see Account#subtractFromBalance(double)
*/
@Override
public void subtractFromBalance(double amount) {
if (getBalance() - amount >= GoldAccount.OVERDRAFT_AMT) {
  
super.subtractFromBalance(amount);
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return \"GoldAccount [interestRate=\" + INTEREST_RATE + \", overdraft=\" + overdraft + \", toString()=\"
+ super.toString() + \"]\";
}
  
@Override
   public void addTransactionInfo(String transactionInfo) {
       String accountNumber = getAccountNumber();
       if (accountNumber != null && !accountNumber.isEmpty()) {
addTransaction(transactionInfo);
  
}
   }
  
}

SavingsAccount.java

package Sample;

/**
* SavingsAccount data class
*
* @author Bullwinkle Moose
* @version 1.0
*/
public class SavingsAccount extends Account {
  
public static final double MIN_AMOUNT = 100.0;
/**
* Default constructor
*/
public SavingsAccount() {
super();
}
/**
* Overloaded constructor
*
* @param balance
* the balance to set
* @param accountNumber
* the account number to set
*/
public SavingsAccount(double balance, String accountNumber) {
super(balance, accountNumber);
}
  
/**
* @return the minAmount constant as a double
*/
public static double getMinAmount() {
return MIN_AMOUNT;
}
  
/*
* (non-Javadoc)
*
* @see Account#subtractFromBalance(double)
*/
@Override
public void subtractFromBalance(double amount) {
if (getBalance() - amount >= MIN_AMOUNT) {
  
super.subtractFromBalance(amount);
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return \"SavingsAccount [toString()=\" + super.toString() + \"]\";
}
  
@Override
   public void addTransactionInfo(String transactionInfo) {
       String accountNumber = getAccountNumber();
       if (accountNumber != null && !accountNumber.isEmpty()) {
addTransaction(transactionInfo);
  
}
   }
  
}

Reporter.java

package Sample;

import java.util.HashMap;

public interface Reporter {
  
   void displayByCode(HashMap<String, BankCustomer> records, String prefix);
   void displayAllCodes(HashMap<String, BankCustomer> records);
   void displayInactiveCodes(HashMap<String, BankCustomer> records);
}

OUTPUT:

Welcome to Bullwinkle\'s Bank.

Choose one of the following options:
1 - Sign In
2 - Deposit
3 - Withdraw
4 - Display Account Info
5 - Exit
> 1
Enter Account Number:
admin
Enter Passcode:
admin
Welcome to Bullwinkle\'s Bank.

Choose one of the following options:
1 - Display Accounts by Code
2 - Display All Codes
3 - Display Inactive Codes
4 - Display Account Totals
5 - Exit
> 1
Enter the code:
gl
GL-123

Choose one of the following options:
1 - Display Accounts by Code
2 - Display All Codes
3 - Display Inactive Codes
4 - Display Account Totals
5 - Exit
> 2
GL-123
CH-123
SA-123

Choose one of the following options:
1 - Display Accounts by Code
2 - Display All Codes
3 - Display Inactive Codes
4 - Display Account Totals
5 - Exit
> 3

Choose one of the following options:
1 - Display Accounts by Code
2 - Display All Codes
3 - Display Inactive Codes
4 - Display Account Totals
5 - Exit
> 4
Total: 350.0

Choose one of the following options:
1 - Display Accounts by Code
2 - Display All Codes
3 - Display Inactive Codes
4 - Display Account Totals
5 - Exit
>

Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now
Account class • The Account class will become an abstract class. • The addTransactionInfo(String) method we become an abstract method. • Each subclass will now

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site