
public class BankMain {
      
      // This program simulates a bank account, using a BankAccount class.
      // First, a new account is created.  Data for creating the account --
      // the initial balance and the annual interest rate -- are input from
      // the user.  Then the user can make a series of deposits and
      // withdrawals.  The user can also request that monthly interest
      // be added to the account balance.  The program ends when the user
      // gives a Quit command (or when a withdrawal produces a negative
      // balance in the account).  The program has almost no error
      // checking.  This is not meant to be a useful program.
      //
      // David Eck,  6 February 1998
   

   public static void main(String[] args) {

      Console console = new Console(); // console window for input/ouput


      // Create a new bank account, using an initial balance and
      // interest rate specified by the user

      console.put("Enter the initial balance in the account: ");
      double initialBalance = console.getlnDouble();

      console.put("Enter the interest rate for the account: ");
      double interestRate = console.getlnDouble();

      console.putln("Opening the account...");

      BankAccount account = new BankAccount(initialBalance, interestRate);


      // Read and process user commands...

      while (true) {

         console.putln();                               // display menu of commands
         console.putln();
         console.putln("Enter D to make a deposit.");
         console.putln("      W to make a withdrawal.");
         console.putln("      I to add monthly interest.");
         console.putln("      Q to quit.");
         console.put("? ");

         char action = console.getlnChar();             // read user's command
         console.putln();

         if (action == 'D' || action == 'd') {          // carry out deposit command
            console.put("Amount to deposit: ");
            double amount = console.getlnDouble(); 
            account.deposit(amount);
            console.putln("OK.  Your balance is $" + account.getBalance());
         }

         else if (action == 'W' || action == 'w') {     // carry out withdrawal command
            console.put("Amount to withdraw: ");
            double amount = console.getlnDouble(); 
            account.withdraw(amount);
            console.putln("OK.  Your balance is $" + account.getBalance());
            if (account.getBalance() < 0) {
               console.putln("WHOOPS!  You're overdrawn... I'm outta here!");
               break;
            }
         }

         else if (action == 'I' || action == 'i') {     // carry out interest command
            account.addMonthlyInterest();
            console.putln("OK.  Your balance is $" + account.getBalance());
         }

         else if (action == 'Q' || action == 'q') {     // carry out interest command 
            console.putln("Thanks for banking with me.");
            console.putln("Your final balance is $" + account.getBalance());
            break;
         }

         else {                                         // unknown command
             console.putln();
             console.putln("Sorry, I don't understand \"" + action + "\".  Try again.");
         }
         
      }  // end while

      console.close();
      
   }  // end main()

} // end of class BankMain