// Arup Guha
// 7/12/06
// Example for BHCSI Intro Java Course - Simulates a Bank Account
// allowing for deposits, withdrawals and balance inquiries.

import java.util.*;

public class Bank3 {

	final public static int QUIT = 4;

	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);

		// Get the starting balance.		
		System.out.println("Welcome to the Bank.");
		System.out.println("What is your starting balance?");
		int balance = stdin.nextInt();
		int choice = 0;
		
		// Continue processing choices until the user quits.
		do {
		
			// Print the menu and get the user's choice.
			System.out.println("Here are your menu options:");
			System.out.println("1. Make a deposit.");
			System.out.println("2. Make a withdrawal.");
			System.out.println("3. Print your balance.");
			System.out.println("4. Quit.");
			System.out.println("Please enter the number of your choice.");
			choice = stdin.nextInt();
			
			// Handle a deposit.
			if (choice == 1) {
				System.out.println("Enter the amount of your deposit.");
				int deposit = stdin.nextInt();
				balance = balance + deposit;
			}
			
			// Handle a withdrawal.
			else if (choice == 2) {
				System.out.println("Enter the amount of your withdrawal.");
				int withdrawal = stdin.nextInt();
				
				// Execute the withdrawal in this case.
				if (withdrawal <= balance)
					balance = balance - withdrawal;
				
				// Print an error message since it can't be done;
				else
					System.out.println("Sorry you don't have that much money. No action was taken.");
			}
			
			// Print out the current balance.
			else if (choice == 3) {
				System.out.println("Your balance is $"+balance+".");
			}
			
			// Print out an error message for an invalid choice.
			else if (choice != QUIT) {
				System.out.println("Sorry that is not a valid choice.");
			}
			
		} while (choice != QUIT);
		
		System.out.println("Thank you for using the bank!");
	}	
}