import java.util.Scanner;
public class Part1 {
public static void main(String[] args) {
// Create new Scanner object to receive user input
Scanner input = new Scanner(System.in);
// Initialize constant value for monthly interest rate
final double MONTHLY_INTEREST_RATE = 0.00417;
// Prompt the user to enter a monthly saving amount
System.out.print("Enter the monthly saving amount: ");
// Get user input for monthly saving amount
double monthlySavingAmount = input.nextDouble();
// Calculates first month account value
double totalAmount = monthlySavingAmount * (1 + MONTHLY_INTEREST_RATE);
System.out.println("After the first month, the account value is " + totalAmount);
// Calculates second month account value
totalAmount = (monthlySavingAmount + totalAmount) * (1 + MONTHLY_INTEREST_RATE);
System.out.println("After the second month, the account value is " + totalAmount);
// Calculates third month account value
totalAmount = (monthlySavingAmount + totalAmount) * (1 + MONTHLY_INTEREST_RATE);
System.out.println("After the third month, the account value is " + totalAmount);
// Calculates fourth month account value
totalAmount = (monthlySavingAmount + totalAmount) * (1 + MONTHLY_INTEREST_RATE);
System.out.println("After the forth month, the account value is " + totalAmount);
// Calculates fifth month account value
totalAmount = (monthlySavingAmount + totalAmount) * (1 + MONTHLY_INTEREST_RATE);
System.out.println("After the fifth month, the account value is " + totalAmount);
// Calculates sixth month account value
totalAmount = (monthlySavingAmount + totalAmount) * (1 + MONTHLY_INTEREST_RATE);
// Displays result
System.out.println("After the sixth month, the account value is " + totalAmount);
}
}
Comments
0 B
|👍
/👎