/** Simulate a bank account. @author Greg Vogl last modified 2003-10-11 */ public class BankAccount2 { /** Create a new bank account with an initial deposit. */ public BankAccount2 (int amount) { deposit(amount); } /** Deposit a positive amount. */ public boolean deposit (int amount) { if (amount <= 0) return false; balance += amount; return true; } /** Withdraw a positive amount that is less than or equal to the balance. */ public boolean withdraw (int amount) { if (amount <= 0 || amount > balance) return false; balance -= amount; return true; } public int getBalance() { return balance; } private int balance; }