MinMaxAccount. A company has written a large class BankAccount with many methods including:
Design a new class MinMaxAccount whose instances can be used in place of a bank account but include new behavior of remembering the minimum and maximum balances ever recorded for the account. The class should have a constructor that accepts a Startup parameter. The bank account’s constructor sets the initial balance on the basis of the startup information. Assume that only debits and credits change an account’s balance. Include these new methods in your class:
package inheritance;
// MinMaxAccount for BankingAccount class
public class MinMaxAccount extends BankingAccount {
int minBalance;
int maxBalance;
public int getMinBalance() {
return minBalance;
}
public int getMaxBalance() {
return maxBalance;
}
public void setMinBalance(int minBalance) {
this.minBalance = minBalance;
}
public void setMaxBalance(int maxBalance) {
this.maxBalance = maxBalance;
}
// create constructor the MinMaxAccount which the Startup Class as argument
public MinMaxAccount(Startup startup) {
super(startup);
minBalance = startup.s_getBalance();
maxBalance = startup.s_getBalance();
}
public void credit(Credit credit) {
super.Credit(credit);
int temp = getBalance();
if (temp < minBalance)
minBalance = temp;
if (temp > maxBalance)
maxBalance = temp;
}
public void debit(Debit debit) {
super.debit(debit);
int temp = getBalance();
if (temp < minBalance)
minBalance = temp;
if (temp > maxBalance)
maxBalance = temp;
}
public static void main(String[] args) {
}
}