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

========================================================

(JAVA)Can anyone fix this code to get exact same

(JAVA)Can anyone fix this code to get exact same

=============

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 0) { balance += 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 = new ArrayList(); for (int i = 1; i

list.add(a); System.out.println(a.toString()); a.displayMonthlyInterests(); a.withdraw(100); a.deposit(200); }

} }

Lab_Exercise 2 [Java Application] /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/bin/java (Feb 5, 2018, 2:37:49 PM) Account Number Initial Balance Matural Balance Rate(%) Date Created 1000 1000.00 1008.78 3.50 Mon Feb 05 14:37:50 PST 2018 Month 1 Month 2 Month 3 1002.92 1005.84 1008.78 A CD Account can't withdraw any cash. You need to close this CD account A CD Account can't make any additional deposit. You may open another CD account. Account Number Initial Balance Matural Balance Rate(%) Date Created 2000 2000.00 2040.33 4.00 Mon Feb 05 14:37:50 PST 2018 Month 1 Month 2 Month 3 Month 4 Month 5 Month 6 2006.67 2013.36 2020.07 2026.80 2033.56 2040.33 A CD Account can't withdraw any cash. You need to close this CD account A CD Account can't make any additional deposit. You may open another CD account. Account Number Initial Balance Matural Balance Rate(%) Date Created 3000 3000.00 3102.78 4.50 Mon Feb 05 14:37:50 PST 2018 Month 1 Month 2 Month 3 Month 4 Month 5 Month 6 Month7 Month 8 Month 9 3011.25 3022.54 3033.88 3045.25 3056.67 3068.14 3079.64 3091.19 3102.78 A CD Account can't withdraw any cash. You need to close this CD account A CD Account can't make any additional deposit. You may open another CD account. Account Number Initial Balance Matural Balance Date Created 4 4000.00 4 6 Mon Feb 05 14:37:50 PST 2018 4016.67 4033.40 4050.21 4067.08 4084.03 4101.05 4118.14 4135.29 4152.52 4169.83 4187.20 A CD Account can't withdraw any cash. You need to close this CD account A CD Account can't make any additional deposit. You may open another CD account. 2 Account Number Initial Balance Matural Balance Date Created 5 5000.00 5355.00 Mon Feb 05 14:37:50 PST 2018 5022.92 5069.07 5092.30 5139.09 5186.30 5210.07 5233.95 5257.94 5330.57 5355.00 A CD Account can't withdraw any cash. You need to close this CD account. A CD Account can't make any additional deposit. You may open another CD account 0 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!