Page 1 of 1

Solution public class MinMaxAccount extends BankingAccount { private int min; private int max; public MinMaxAccount(Star

Posted: Mon Jun 06, 2022 5:41 pm
by answerhappygod
Solution Public Class Minmaxaccount Extends Bankingaccount Private Int Min Private Int Max Public Minmaxaccount Star 1
Solution Public Class Minmaxaccount Extends Bankingaccount Private Int Min Private Int Max Public Minmaxaccount Star 1 (62.4 KiB) Viewed 15 times
Solution public class MinMaxAccount extends BankingAccount { private int min; private int max; public MinMaxAccount(Startup s) { //pass s to Banking Account(s) so MixMax accounts are setup like Banking accounts super(s); //start the min and max for this account as the starting balance min getBalance(); max = getBalance(); } //accessors for min/max public int getMin() { return min; } public int getMax() { return max; } //override the functionality of debit and credit to account for tracking min/max public void debit(Debit d) { super.debit(d); updateMinMax(); } public void credit (Credit c) { super.credit(c); updateMinMax(); } //helper method for updating balance since needed in multiple places private void updateMinMax() { min = Math.min(min, getBalance()); max = Math.max(max, getBalance()); } } Answer the following questions: 1. What is the purpose of calling super(s) in the MinMaxAccount constructor? 2. Why does calling getBalance()) in the MinMaxAccount class work when it does not appear in this file? 3. What is the purpose of calling super. credit(c) in the MinMaxAccount class's credit method? 4. Why is there an updateMinMaxMethod() method and why do you think it is private?