>>
Add a static method Account consolidate(Account acct1, Account acct2) to your Account class that creates a new account whose balance is the sum of the balances in acct1 and acct2 and closes acct1 and acct2. The new account should be returned.
<<
Break this down :
>>Add a static method Account consolidate(Account acct1, Account acct2) to your Account class
<<
public Account consolidate(Account account1, Account account2)
{ /* Code */ }
Next part of the statement :
>>
Account class creates a new account
<<
public Account consolidate(Account account1, Account account2)
{
Account accountSum;
}
whose balance is the sum of the balances in acct1 and acct2 and closes acct1 and acct2. The new account should be returned.
public Account consolidate(Account account1, Account account2)
{
Account accountSum;
accountSum.balance = account1.getBalance() + account2.getBalance();
//make account1 and account close()
}
See how that works. Break down the question, and it becomes simpler.
So you need to sum the balance, and close account1 and account2.
By the way, You should make account1 and account2 = null when its closed.