package homework5;
/********************************
** Author: Bryan Orr
** ID: 238772
** Email: bryan@bryanorr.net
** Date: 10/13/12
** Course: CPSC-6548-01_java_programming
** FileName: SavingsAccount.java
** Homework: 5
** Description:
** main menu
********************************/
//********** Imports **********\\
import homework5.Account.BaseAccount;
import homework5.Account.AccountCreator;
import java.util.Scanner;
public class menu {
private static Integer accnt_selection = 0;
private static Integer main_selection = 0;
private static Scanner input = new Scanner(System.in);
public static final void show_account_menu() {
System.out.println("\nAccounts Menu");
System.out.println("1. Checking");
System.out.println("2. Savings");
System.out.println("3. Exit system");
System.out.printf("Selection: ");
accnt_selection = input.nextInt();
//what was selected and show appropriate response
BaseAccount account;
switch(accnt_selection.intValue()) {
case 1: // checking
account = AccountCreator.createChecking(0);
main_menu_loop(account,"Checking");
break;
case 2: // savings
account = AccountCreator.createSavings(0);
main_menu_loop(account,"Savings");
break;
default:
accnt_selection = 3;
break;
}
}
public static final void show_main_menu(String type) {
System.out.println("\n" + type + " Menu");
System.out.println("1. Get balance");
System.out.println("2. Withdraw Funds");
System.out.println("3. Deposit Funds");
System.out.println("4. Return to Accounts Menu");
System.out.printf("Selection: ");
main_selection = input.nextInt();
}
public static final void show_status(int return_status) {
if(return_status == -2) {
System.out.println("Insufficient funds for this transaction.");
} else if(return_status == -1) {
System.out.println("Invalid amount");
} else if(return_status == 0) {
System.out.println("Transaction Successful");
} else {
System.out.println("An unknown error (" + return_status + ") has occured");
}
}
public static final void main_menu_loop(BaseAccount account, String type) {
//show the menu and get customer selection
show_main_menu(type);
while(main_selection.intValue() !=4) {
//what was selected and show appropriate response
Double amt = 0.00;
switch(main_selection.intValue()) {
case 1: // customer wants balance
System.out.println(account);
break;
case 2: // customer wants to withdraw funds
//get amount to withdraw
System.out.printf("\nEnter transaction amount: ");
amt = input.nextDouble();
show_status(account.do_debit(amt));
break;
case 3: // customer wants to deposit funds
//get amount to deposit
System.out.printf("\nEnter transaction amount: ");
amt = input.nextDouble();
show_status(account.do_credit(amt));
break;
default:
main_selection = 4;
break;
}
show_main_menu(type);
};
}
public static void main(String[] args) {
show_account_menu();
while(accnt_selection.intValue() !=3) {
show_account_menu();
};
System.out.println("Goodbye");
input.close();
}
}