//package Chap4;
import java.io.*;

// CSC108 Chapter 4, Question 18
// Name:  Iam Me         Student ID: 555555555
// Tutor: Andria Hunter  Prof: Ken Jackson
//
// Program Description: This program uses the Bank_Account2 class
//     to create two bank account objects.  It then uses the 
//     debit, credit, and get_balance methods on these objects.
//     This program is different than the program that uses the 
//     Bank_Account class, because the values are read from input.
//     This program uses two classes: one for the bank account
//     and its operations (Bank_Account2), and one that contains
//     the main method (CIBC_Bank2).

// The Bank_Account2 class contains a variable that stores the
// current balance, and methods that can be used to deposit,
// withdraw, and display the current balance.

class Bank_Account2 {

   // Stores the current balance of the Bank_Account2 object.
   private double balance;

   // Constructor to initialize the account balance.
   public Bank_Account2 (double start_balance) {
      balance = start_balance;
   }

   // Method to decrease the account balance by the amount passed.
   public void debit (double amount) {
      balance = balance - amount;
   }

   // Method to increase the account balance by the amount passed.
   public void credit (double amount) {
      balance = balance + amount;
   }

   // Method that returns the current balance of the account.
   public double get_balance () {
      return balance;
   }
}

// The CIBC_Bank2 class contains one main method where program execution
// starts.  The two bank accounts are created in this method.

class CIBC_Bank2 {

   // Main method to create two bank account (Bank_Account2) objects,
   // and to perform various methods on these objects.  Unlike the
   // program that uses the Bank_Account class, the values are read
   // from input.

   public static void main (String[] args) throws IOException {

      // Declare stdin so data can be read from input.
      DataInputStream stdin = new DataInputStream (System.in);

      //---------
      // Create account 1 and use debit and credit on this account.

      // Enter the starting balance of account 1 from stdin
      System.out.println ("Enter starting balance of account 1: ");
      double start1 = new Double(stdin.readLine()).doubleValue();
      Bank_Account2 account1 = new Bank_Account2 (start1);
      System.out.println ("Account 1 balance: "+account1.get_balance());

      // Deposit into Account 1 
      System.out.println ("\nEnter deposit amount for account 1: ");
      double deposit1 = new Double(stdin.readLine()).doubleValue();
      account1.credit(deposit1);
      System.out.println ("Account 1 balance: "+account1.get_balance());
      
      // Withdraw from Account 1 
      System.out.println ("\nEnter withdrawl amount for account 1: ");
      double withdraw1 = new Double(stdin.readLine()).doubleValue();
      account1.debit(withdraw1);
      System.out.println ("Account 1 balance: "+account1.get_balance());
      
      //---------
      // Create account 2 and use debit and credit on this account.

      // Enter the starting balance of account 2 from stdin
      System.out.println ("\nEnter starting balance of account 2: ");
      double start2 = new Double(stdin.readLine()).doubleValue();
      Bank_Account2 account2 = new Bank_Account2 (start2);
      System.out.println ("Account 2 balance: "+account2.get_balance());

      // Deposit into Account 2 
      System.out.println ("\nEnter deposit amount for account 2: ");
      double deposit2 = new Double(stdin.readLine()).doubleValue();
      account2.credit(deposit2);
      System.out.println ("Account 2 balance: "+account2.get_balance());
      
      // Withdraw from Account 2 
      System.out.println ("\nEnter withdrawl amount for account 2: ");
      double withdraw2 = new Double(stdin.readLine()).doubleValue();
      account2.debit(withdraw2);
      System.out.println ("Account 2 balance: "+account2.get_balance());
      
      //---------
      // Report balances of the two accounts

      System.out.println ("\nAccount 1 final balance: "+
                                    account1.get_balance());
      System.out.println ("Account 2 final balance: "+
                                    account2.get_balance());
   }
}

