Solution public class MinMaxAccount extends BankingAccount { private int min; private int max; public MinMaxAccount(Star
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Solution public class MinMaxAccount extends BankingAccount { private int min; private int max; public MinMaxAccount(Star
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?
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