
// A program that can help the user balance a checking account.

public class BalanceAccount {

   public static void main(String[] args) {
   
      Account account;  // An object representing the bank account.
      boolean done;     // Flag for checking whether user wants to quit.
      int choice;       // Number of user's choice from a menu.
      double amount;    // An amount read from the user, used for various purposes.
      double rate;      // An interest rate entered by the user.
   
      System.out.println();
      System.out.println();
      System.out.println("This program will help you balance your checking account.");
      System.out.println();
      System.out.println("Please enter the opening balance in your account.");
      System.out.println();
      System.out.print("? ");
      amount = TextIO.getlnDouble();
      
      account = new Account(amount);      
      
      System.out.println();
      System.out.println("Now use the following menu to record your deposits,");
      System.out.println("withdrawals, and interest and to see your balance:");
      System.out.println("");
   
      done = false;
   
      while (!done) {
      
         System.out.println();
         System.out.println();
         System.out.println("Choose one of the following options:");
         System.out.println();
         System.out.println("   1.  Make a deposit.");
         System.out.println("   2.  Make a withdrawal.");
         System.out.println("   3.  Add interest.");
         System.out.println("   4.  See the balance.");
         System.out.println("   5.  Exit from this program.");
         System.out.println();
         System.out.print("Enter the number of your choice:  ");
         
         switch ( TextIO.getlnInt() ) {
            case 1:
               System.out.print("Enter the amount of the deposit:  $");
               amount = TextIO.getlnDouble();
               account.deposit(amount);
               break;
            case 2:
               System.out.print("Enter the amount of the withdrawal:  $");
               amount = TextIO.getlnDouble();
               account.withdraw(amount);
               break;
            case 3:
               System.out.println("Please enter the interest rate as a decimal,");
               System.out.println("for example:  0.05  rather than  5%");
               System.out.println();
               System.out.print("Enter the interest rate:  ");
               rate = TextIO.getlnDouble();
               account.addInterest(rate);
               break;
            case 4:
               amount = account.getBalance();
               System.out.println();
               System.out.println("*** Your balance is  $" + amount);
               if (amount < 0)
                  System.out.println("*** Warning: you are overdrawn!!");
               break;
            case 5:
               done = true;
               break;
            default:
               System.out.println();
               System.out.println("Illegal option.  Try again!");
               break;
         }
         
      } // end while
   
   } // end main

} // end class BalanceAccount
