Can you please help me check my error? ackage assignment4; import java.text.Deci
ID: 3598447 • Letter: C
Question
Can you please help me check my error?
ackage assignment4;
import java.text.DecimalFormat;
import java.util.Scanner;
/**
*
* @author User01
*/
public class Assignment4 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
System.out.print("Enter the initial deposit amount: ");
double Deposit = input.nextDouble();
System.out.print(" Enter annual percentage yield:") ;
double Percentage = input.nextDouble();
System.out.print("Enter maturity period (number of months):");
double Period = input.nextDouble();
System.out.println("Month" + " "+ " "+ "CD Value");
for (int i = 1; i <= Period; i++){
double value=(Deposit+Deposit*Percentage/1200)*(i);
System.out.println(i+ " "+" "+df.format(value));
}
}
}
}
}
}
Explanation / Answer
Assignment4.java
package a10;
import java.text.DecimalFormat;
import java.util.Scanner;
/**
*
* @author User01
*/
public class Assignment4 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
System.out.print("Enter the initial deposit amount: ");
double Deposit = input.nextDouble();
System.out.print(" Enter annual percentage yield:") ;
double Percentage = input.nextDouble();
System.out.print("Enter maturity period (number of months):");
double Period = input.nextDouble();
double value = Deposit;
System.out.println("Month" + " "+ " "+ "CD Value");
for (int i = 1; i <= Period; i++){
value= value + (Deposit*Percentage)/1200;
System.out.println(i+ " "+" "+df.format(value));
}
}
}
Output:
Enter the initial deposit amount: 10000
Enter annual percentage yield:5.75
Enter maturity period (number of months):18
Month CD Value
1 10047.92
2 10095.83
3 10143.75
4 10191.67
5 10239.58
6 10287.50
7 10335.42
8 10383.33
9 10431.25
10 10479.17
11 10527.08
12 10575.00
13 10622.92
14 10670.83
15 10718.75
16 10766.67
17 10814.58
18 10862.50