Question 2-4

Write a method that, given an Account, generates and returns a duplicate account holding the same amount of money. Use the Account object interface described as follow.

Constructors
Account() Creates a new account holding no money.
Object methods
double getBalance() Returns the amount of money held in the object account.
void deposit(double amt) Adds amt dollars to the object account's balance.
void withdraw(double amt) Subtracts amt dollars from the object account's balance.
public static Account duplicate(Account acct) {


}

Solution

public static Account duplicate(Account acct) {
    Account ret = new Account();
    ret.deposit(acct.getBalance());
    return ret;
}

Back to Review for Quiz 2