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

A company has written a large class BankingAccount with many methods including:

ID: 3824123 • Letter: A

Question

A company has written a large class BankingAccount with many methods including: Design a new class MinMaxAccount whose instances can be used in place of a BankingAccount object but include new behavior of remembering the minimum and maximum balances ever recorded for the account. You should provide the same methods as the superclass, as well as the following new behavior: The account's constructor sets the initial balance based on the startup information. Assume that only the debit and credit methods change an account's balance.

Explanation / Answer

NOte: In your debit method also adds money to balance. How can debit as well as credit add money to balance.

//anyways i have changed it.

//i have also add a balances list in bankaccount class which reciords the balances whenever a credit or debit occurs.

import java.util.LinkedList;
import java.util.List;

public class BankingAccount {
private int balance;
  
  
public List<Integer> balances;
private List<String> historyTransaction;
private List<String> historyBalance;
  
public BankingAccount() {
historyTransaction = new LinkedList<String>();
historyBalance = new LinkedList<String>();
balances=new LinkedList<Integer>();
  
}
  
public BankingAccount(Startup s) {
this.balance = s.startup_getBalance();
  
balances=new LinkedList<Integer>();

balances.add( this.balance);

  
  
historyTransaction = new LinkedList<String>();
historyBalance = new LinkedList<String>();
  
historyTransaction.add(valueToHistory(s.startup_getBalance()));
historyBalance.add(toString());
}
  
public void debit(Debit d) {
balance -= d.debit_getBalance();
  
balances.add(this.balance);
  
historyTransaction.add(valueToHistory(d.debit_getBalance()));
historyBalance.add(toString());
}
  
public void credit(Credit c) {
balance += c.credit_getBalance();
  
balances.add(this.balance);

  
historyTransaction.add(valueToHistory(c.credit_getBalance()));
historyBalance.add(toString());
}
  
public int getBalance() {
return balance;
}
  
public boolean equals(Object o) {
if(o instanceof BankingAccount) {
return (this.getBalance() == ((BankingAccount) o).getBalance());
}
return false;
}
  
private String valueToHistory(int value) {
int absValue = Math.abs(value);
return (value < 0 ? "(-" : "") + (absValue / 100) + "." + (absValue % 100 / 10) + (absValue % 100 % 10) + (value < 0 ? ")" : " ");
}
  
public String toString() {
int absBalance = Math.abs(balance);
return (balance < 0 ? "-" : "") + "$" + (absBalance / 100) + "." + (absBalance % 100 / 10) + (absBalance % 100 % 10);
}
  
public String historyBalanceToString() {
/*int maxLength = 0;
for(String piece : historyBalance) {
maxLength = Math.max(maxLength, piece.length());
}*/
int maxLength = 8;
  
String build = "";
for(int i = 0; i < historyBalance.size(); i++) {
for(int j = 0; j < maxLength - historyBalance.get(i).length(); j++) {
build += " ";
}
build += historyBalance.get(i);
if(i != historyBalance.size() - 1) {
build += " ";
}
}
  
return build;
}
  
public String historyTransactionToString() {
String total = toString() + " ";
  
int maxLength = 0;
for(String piece : historyTransaction) {
maxLength = Math.max(maxLength, piece.length() + 2);
}
maxLength = Math.max(maxLength, total.length() + 2);
  
String build = "";
for(int i = 0; i < historyTransaction.size() - 1; i++) {
for(int j = 0; j < maxLength - historyTransaction.get(i).length(); j++) {
build += " ";
}
build += historyTransaction.get(i);
build += " ";
}
  
build += "+";
for(int i = 0; i < maxLength - (historyTransaction.get(historyTransaction.size() - 1).length() + 1); i++) {
build += " ";
}
build += historyTransaction.get(historyTransaction.size() - 1);
build += " ";
  
for(int i = 0; i < maxLength; i++) {
build += "-";
}
build += " ";
  
for(int i = 0; i < maxLength - total.length(); i++) {
build += " ";
}
build += total;
  
return build;
}
  

   public static class Startup {
private int balance;
  
public Startup(int balance) {
this.balance = balance;
}
  
public int startup_getBalance() {
return balance;
}
}
  
public static class Debit {
private int balance;
  
public Debit(int balance) {
this.balance = balance;
}
  
public int debit_getBalance() {
return balance;
}
}
  
public static class Credit {
private int balance;
  
public Credit(int balance) {
this.balance = balance;
}
  
public int credit_getBalance() {
return balance;
}
}
}

------------------------------------------------------------------------------
public class MinMaxAccount extends BankingAccount {

  
  
   public MinMaxAccount(Startup s)
   {
       Credit c=new Credit(s.startup_getBalance());
       this.credit(c);
   }
  
   public int getMin()
   {
       int min=this.getBalance();
      
   for(int bal: this.balances)
   {
       if(min>bal)
       {
           min=bal;
       }
   }
  
   return min;
   }
  
   public int getMax(){

       int max=this.getBalance();
      
   for(int bal: this.balances)
   {
       if(max<bal)
       {
           max=bal;
       }
   }
  
   return max;
   }
  
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote