Counting Transactions

File Account.java contains a definition for a simple bank account class with methods to withdraw, deposit, get the balance and account number, and print a summary. (This is very much like lab 1.) Save it to your directory and study it to see how it works.

Suppose the bank wanted to keep track of the total number of deposits and withdrawals (separately) for each day, and the total amount deposited and withdrawn. Write code to do this as follows:

  1. Add four private static variables to the Account class, one to keep track of each value above (number and total amount of deposits, number and total of withdrawals). Note that since these variables are static, all of the Account objects share them. This is in contrast to the instance variables that hold the balance, name, and account number; each Account has its own copy of these. Numeric static and instance variables are initialized to 0 by default.
  2. Add public methods to return the values of each of the variables you just added, e.g., public static int getNumDeposits().
  3. Modify the withdraw and deposit methods to update the appropriate static variables at each withdrawal and deposit.
  4. File ProcessTransactions.java contains a program that creates and initializes two Account objects and enters a loop that allows the user to enter transactions for either account until asking to quit. Modify this program as follows:

Go back to lab2 index page