/** * This class represents a single bank account */ public class BankAccount{ // Instance variables private final double INTEREST_RATE = 0.03; private double balance; private String ownerName; private int accountNumber; /** * Constructs a new bank account * @param theName The name of the owner of the account * @param theAccountNum The account number * @param initialBalance The initial balance */ public BankAccount(String theName, int theAccountNum, double initialBalance){ balance = initialBalance; ownerName = theName; accountNumber = theAccountNum; } /** * Constructs a new bank account with initial balance of $0 * @param theName The name of the owner of the account * @param theAccountNum The account number */ public BankAccount(String theName, int theAccountNum){ balance = 0.0; ownerName = theName; accountNumber = theAccountNum; } /** * Returns the account number * @return The account id number */ public int getAccountNumber(){ return accountNumber; } /** * Returns the name of the account owner * @return The name of the owner of the account */ public String getOwnerName(){ return ownerName; } /** * Returns the current balance * @return The current balance of the account */ public double getBalance(){ return balance; } /** * Adds interest to the account * @return The balance after interest has been added */ public double addInterest(){ double interest = balance * INTEREST_RATE; balance = balance + interest; return balance; } /** * Deposits money into the account * @param amount The amount of money to be deposited * @return The current balance after the deposit */ public double deposit(double amount){ balance = balance + amount; return balance; } /** * Withdraws money from the account * @param amount The amount of money to be withdrawn * @return The current balance after the withdrawal */ public double withdrawal(double amount){ balance = balance - amount; return balance; } /** * Returns a String representation of the bank account * @return A string representing the state of the bank account */ public String toString(){ return "[current balance=" + balance + "]"; } }