Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

9. MinMaxAccount. A company has written a large class BankAccount with many meth

ID: 3875497 • Letter: 9

Question

9. MinMaxAccount. A company has written a large class BankAccount with many methods includin public BankAccount (Startups) public void debit(Debit d) public void credit (Credit c) public int getBalance() Constructs a BankAccount object using information in s Records the given debit Records the given credit Returns the current balance in pennies Design a new class MinMaxáccount whose instances can be used in place of a bank account but include new betayir of remembering the minimum and maximum balances ever recorded for the account. The class should have a tor that accepts a Startup parameter. The bank account's constructor sets the initial balance on the basis of information. Assume that only debits and credits change an account's balance. Include these new methods in your ciais construc the startup public int getMin() public int getMax() Returns the minimum balance in pennies Returns the maximum balance in pennies

Explanation / Answer

This code is written in Java.

public class MinMaxAccount extends BankAccount


{ private int minBalance; //variable for minimum balance

private int maxBalance; //variable for maximum balance

public MinMaxAccount(Startup s)

{

super(s);

minBalance = super.getBalance();

maxBalance = super.getBalance();

}

// record the given Debit object

public void debit (Debit d)

{

//If balance is less than the minimum balance, set minimum balance to current balance.

if ((super.balance = super.getBalance() - d.getAmount()) < this.getMin())

{

this.minBalance = super.getBalance();

}

//set most recent action to date

mostRecentAction = d.getDate();

}

// record the given Credit object

public void credit (Credit c)

{

//If balance is greater than the max balance, set max balance to current balance.

if ((super.balance = super.getBalance() + c.getAmount()) > this.getMax())

{

this.maxBalance = super.getBalance();

}

mostRecentAction = c.getDate();

}

//getMin() returns minimum balance

public int getMin()

{

return this.minBalance;

}//end of getMin()

//getMax() returns minimum balance

public int getMax()

{

return this.maxBalance;

}//end of getMax()

//printBalance() of account

public void printBalance(){

System.out.format("Balance: %d Maximum Balance: %d Minimum Balance: %d ", this.getBalance(), this.getMax(), this.getMin());

}

}