JeffGrigg icon

Part1 of Interest Calcuation

JeffGrigg | PRO | 09/23/18 06:53:07 PM UTC | 0 ⭐ | 961 👁️ | Never ⏰ | []
Java 5 |

0 B

|

None

|

0 👍

/

0 👎

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

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎