public class BankAccount
{
private double balance;
public BankAccount()
{ balance = 0; }
public BankAccount(double acctBalance)
{ balance = acctBalance; }
public void deposit(double amount)
{ balance += amount; }
public void withdraw(double amount)
{ balance -= amount; }
public double getBalance()
{ return balance; }
}
public class SavingsAccount : BankAccount
{
private double interestRate;
public SavingsAccount()
{ /* implementation not shown */ }
public SavingsAccount(double acctBalance, double rate)
{ /* implementation not shown */ }
public void addInterest() //Add interest to balance
{ /* implementation not shown */ }
}
public class CheckingAccount : BankAccount
{
private const double FEE = 2.0;
private const double MIN_BALANCE = 50.0;
public CheckingAccount(double acctBalance)
{ /* implementation not shown */ }
/** FEE of $2 deducted if withdrawal leaves balance less
* than MIN_BALANCE. Allows for negative balance. */
public void withdraw(double amount)
{ /* implementation not shown */ }
}
A new method is added to the BankAccount class.
/** Transfer amount from this BankAccount to another BankAccount.
* Precondition: balance > amount
* @param another a different BankAccount object
* @param amount the amount to be transferred
*/
public void transfer(BankAccount another, double amount)
{
withdraw(amount);
another.deposit(amount);
}
A program has these declarations:
BankAccount b = new BankAccount(650);
SavingsAccount timsSavings = new SavingsAccount(1500, 0.03);
CheckingAccount daynasChecking = new CheckingAccount(2000);
Which of the following will transfer money from one account to another without error?
I b.transfer(timsSavings, 50);
II timsSavings.transfer(daynasChecking, 30);
III daynasChecking.transfer(b, 55);
(A) I only
(B) II only
(C) III only
(D) I, II, and III
(E) None