/** * A simple bank account. (Version 1 without constructors.) * * @author Hal Perkins * @version July 8, 2001 */ public class BankAccount { String accountName = ""; // account owner's name int accountNumber = 0; // account number double balance = 0.0; // current account balance in dollars /** Set account owner's name * @param newAccountName the new name of this account */ public void setAccountName(String newAccountName) { this.accountName = newAccountName; } /** Set account number * @param number new number for this account */ public void setAccountNumber(int number) { this.accountNumber = number; } /** Deposit money in this account * @param amount amount of money to deposit in dollars */ public void deposit(double amount) { this.balance = this.balance + amount; } /** Get account balance. * @return Current account balance */ public double getBalance() { return this.balance; } /** Withdraw money from account. Only allow user to withdraw up to the * current account balance. * @param request amount requested * @return amount actually withdrawn */ public double withdraw(double request) { double amountWithdrawn; if (this.balance >= request) { amountWithdrawn = request; this.balance = this.balance - request; } else { amountWithdrawn = this.balance; this.balance = 0.0; } return amountWithdrawn; } }