package savingsAccount;

import java.util.Scanner;

/**
 * <p>Sample "savings account" program for CIT591.</p>
 * <p>The user starts with a balance of zero, and can perform
 * the following operations:
 * <ul>
 *   <li>D -- Deposit money into the account</li>
 *   <li>W -- Withdraw money from the account</li>
 *   <li>C -- Check how much money is in the account</li>
 *   <li>Q -- Quit the program</li>
 * </ul>
 * The above letters may also be entered in lowercase.</p>
 * 
 * @author Dave Matuszek
 * @version Sep 15, 2008
 */
public class SavingsAccount {

    Scanner scanner;

    public static void main(String[] args) {
        new SavingsAccount().run();
    }

    void run() {
        double balance = 0;
        scanner = new Scanner(System.in);

        System.out.print("What do you want to do (CDWQ)? ");
        String request = scanner.next();

        while (request.charAt(0) != 'Q' && request.charAt(0) != 'q') {
            
            if (request.charAt(0) == 'C' || request.charAt(0) == 'c') {
                System.out.println("Your balance is " + balance);
            }
            else if (request.charAt(0) == 'D' || request.charAt(0) == 'd') {
                System.out.print("Enter an amount: ");
                double amount = scanner.nextDouble();
                balance = balance + amount;
            }
            else if (request.charAt(0) == 'W' || request.charAt(0) == 'w') {
                System.out.print("Enter an amount: ");
                double amount = scanner.nextDouble();
                if (amount > balance) {
                    System.out.println("Sorry, Dave, I can't do that.");
                }
                else {
                    assert amount <= balance;
                    balance = balance - amount;
                }
            }
            System.out.print("What do you want to do (CDWQ)? ");
            request = scanner.next();
        }
    }

}
