ATM.java
/**
* @author rex
* @version 1.0
* @date Feb 8 2017
* @bool loggedIn, boolean for the state of user log in
* @param accountNumber, String, a placeholder initialize for test purpose
*/
public class ATM {
private InputReader scanner;
Bank firstBank;
boolean loggedIn = false;
String accountNumber;
/**
* 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() {
scanner = new InputReader();
initialize();
}
/*
public ATM(InputReader scanner) {
super();
this.scanner = scanner;
}
*/
/**
* Displays a BankCustomer's account information if the customer has been
* previously verified.
*
* @param customer
*/
public void displayAccountInformation(BankCustomer customer) {
BankCustomer temp = firstBank.getCustomerDetail(accountNumber);
System.out.println(temp);
}
/**
* Adds Customer references to the Bank HashMap as seed data for testing.
*/
public void initialize() {
firstBank = new Bank();
BankCustomer dog = new BankCustomer("Darby", "Dog", "ST-123", "123");
BankCustomer cat = new BankCustomer("Freckle", "Cat", "ST-780", "789");
BankCustomer dog2 = new BankCustomer("Myia", "Dog", "ST-456", "456");
firstBank.createAccount(dog);
firstBank.createAccount(cat);
firstBank.createAccount(dog2);
System.out.println("Just for verification, "
+ "This are all the customers in the list");
firstBank.displayAllCustomers();
}
/**
* The primary application processor. All application functions are called
* from here. Uses a loop to prompt users to perform banking transactions.
* Must use switch/case selection to determine uses choices.
*/
public void run() {
int choice;
//char quit = 'n';
boolean quit = true;
System.out.println("\n\n");
if (!loggedIn) {
System.out.println("Welcome to Bullwinkle's Bank");
}
System.out.println("Choose one of the following options:\n"
+ "1 - Sign In\n"
+ "2 - Deposit\n"
+ "3 - Withdraw\n"
+ "4 - Display Account\n"
+ "5 - Exit");
while (quit) {
choice = scanner.getIntInput();
if (choice < 1 || choice > 5) {
choice = 0;
}
switch (choice) {
case 0:
System.out.println("ERROR: Choose from 1 ~ 5");
break;
case 1:
verifyCustomer();
break;
case 2:
transactDeposit();
break;
case 3:
transactWithdraw();
break;
case 4:
displayAccountInfo();
break;
case 5:
System.out.println("DEBUG: Displaying all the accounts"
+ " in the bank.");
listAllCustomers();
quit = false;
loggedIn = false;
break;
}
}
}
public void displayAccountInfo() {
if (!loggedIn) {
System.out.println("ERROR: You must login before your"
+ " perform a transaction");
run();
return;
}
firstBank.displayCustomerInformation(firstBank.getCustomerDetail(accountNumber));
run();
}
public void listAllCustomers()
{
System.out.println("Thank you for banking at BullWinkle's Bank");
Bank.displayAllCustomers();
}
/**
* 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 (!loggedIn) {
System.out.println("ERROR: You must login before "
+ "your perform a transaction");
run();
return;
}
System.out.println("Enter Amount to deposit");
double deposit = scanner.getDoubleInput();
firstBank.deposit(accountNumber, deposit);
run();
}
/**
* 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");
String account = scanner.getStringInput();
System.out.println("Enter Passcode");
String password = scanner.getStringInput();
BankCustomer auth = firstBank.getCustomerDetail(account);
System.out.println("\n\n");
if (auth.getPasscode().equals(password)) {
System.out.println("<!---- Welcome to Bullwinkle's Bank ---> Dear " + auth.getFirstName());
loggedIn = true;
accountNumber = account;
} else {
System.out.println("ERROR: Either account number or password is not correct");
}
run();
}
/**
* 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 (!loggedIn) {
System.out.println("ERROR: You must login before your perform a transaction");
run();
return;
}
System.out.println("Enter the amount to withdraw");
double amount = scanner.getDoubleInput();
firstBank.withdraw(accountNumber, amount);
run();
}
/**
* Main method calls the class default constructor.
*
* @param args, for program arguments (not used)
*/
public static void main(java.lang.String[] args) {
ATM test = new ATM();
test.run();
}
}
No comments:
Post a Comment