Question: (JAVA)Can anyone fix this code to get exact same output as following sample output? The problem I found are 1. Matural Balance (the result is
(JAVA)Can anyone fix this code to get exact same output as following sample output?
The problem I found are
1. Matural Balance (the result is wrong) is not correct with this code below.
2. Rate (0.0 instead of 0.00) is not correct with this code below.
3. Initial Balance (the result is wrong) is not correct with this code below.
4. need to get rid of the StringBuilder in toString() method, but, have to use to String.format() or string concatenation to get the output.
========================================================
sample output
========================================================


=============
code
=============
package account;
import java.util.Date;
public class Account { private int id; private double balance; private Date dateCreated; private static double annualInterestRate; private double initialBalance;
public Account () { id = 0; balance = 0; initialBalance = 0; dateCreated = new Date(); annualInterestRate = 0.0; }
public Account (int id, double balance) { this.id = id; this.balance = balance; initialBalance = balance; dateCreated = new Date(); annualInterestRate = 0.0; }
// id public void setId(int id) { this.id = id; }
public int getId() { return id; }
// bal public void setBalance(double balance) { this.balance = balance; }
public double getBalance() { return balance; }
public double getInitialBalance() { return initialBalance; }
// annual public static double getAnnualInterestRate() { return annualInterestRate; }
public static void setAnnualInterestRate(double annualInterest) { Account.annualInterestRate = annualInterest; }
// date public Date getDateCreated() { return dateCreated; }
public double getMonthlyInterest() { return this.balance * annualInterestRate / 1200; }
// w,d public void withdraw(double amount) { if (amount
public void deposit(double amount) { if (amount
CDAccount
package account;
public class CDAccount extends Account {
private int duration; private double CDannualInterestRate;
public CDAccount () {
}
public CDAccount (int id, double balance, int duration) { super(id, balance); this.duration = duration; setCDannualInterestRate();
}
public int getDuration() { return duration; }
public void setDuration(int duration) { this.duration = duration; setCDannualInterestRate();
}
public double getCDannualInterestRate() { return CDannualInterestRate; }
private void setCDannualInterestRate() { double cDannualInterestRateCalculated = 0; int multiplier = (this.duration - this.duration % 3) / 3; cDannualInterestRateCalculated = this.getAnnualInterestRate() + 0.5 * multiplier; this.CDannualInterestRate = cDannualInterestRateCalculated; }
@Override public final void withdraw(double amount) { System.out.println("A CD Account can't withdraw an cash. You need to close this CD Account"); }
@Override public final void deposit(double amount) { System.out.println("A CD Account can't make any additional deposit. You may open another CD Account"); }
public double getMatureBalance() { double matureBalance = this.getBalance() * (1 + this.getMonthlyInterestRate() * duration); return matureBalance; }
public double getMonthlyInterestRate() { return (this.getCDannualInterestRate() / 1200); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); System.out.println(); sb.append("Account Number\t\tInitial Balance\t\tMatural Balance\t\tRate(%)\t\tDate Created "); sb.append("==================================================================================================================== "); sb.append("\t" + this.getId()); sb.append("\t\t" + this.getInitialBalance()); sb.append("\t\t\t" + this.getMatureBalance()); sb.append("\t\t\t" + this.getCDannualInterestRate()); sb.append("\t\t" + this.getDateCreated()); return sb.toString(); }
public void displayMonthlyInterests() { double matureBalance = 0; System.out.println(); for (int i = 1; i
}
Assignment5
package account;
import java.util.ArrayList;
public class Assignment5 {
public static void main(String[] args) { ArrayList list.add(a); System.out.println(a.toString()); a.displayMonthlyInterests(); a.withdraw(100); a.deposit(200); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
