//Copyright (c) 2002 Art Gittleman //This example is provided WITHOUT ANY WARRANTY //either expressed or implied. /* Modifies the BankAccount class to include a class variable * to store the total number of successful Deposit, Withdraw, * and GetBalance operations by any Acct object. */ public class Acct { private double balance; // instance variable private static int transactions = 0; // class variable public Acct() { balance = 0; } public Acct(double initialAmount) { balance = initialAmount; } // Increments transactions public void Deposit(double amount) { // instance method balance += amount; transactions++; } /* Only increments transactins if the * withdrawal is successful. */ public double Withdraw(double amount) { if (balance >= amount){ balance -= amount; transactions++; return balance; } else return -1.0; } public double GetBalance() { transactions++; return balance; } public static int GetTransactionCount() { // class method return transactions; } }