Advertisement
JeffGrigg

Part1 of Interest Calcuation

Sep 23rd, 2018
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.93 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Part1 {
  4.     public static void main(String[] args) {
  5.         // Create new Scanner object to receive user input
  6.         Scanner input = new Scanner(System.in);
  7.         // Initialize constant value for monthly interest rate
  8.         final double MONTHLY_INTEREST_RATE = 0.00417;
  9.  
  10.         // Prompt the user to enter a monthly saving amount
  11.         System.out.print("Enter the monthly saving amount: ");
  12.         // Get user input for monthly saving amount
  13.         double monthlySavingAmount = input.nextDouble();
  14.  
  15.         // Calculates first month account value
  16.         double totalAmount = monthlySavingAmount * (1 + MONTHLY_INTEREST_RATE);
  17.         System.out.println("After the first month, the account value is " + totalAmount);
  18.         // Calculates second month account value
  19.         totalAmount = (monthlySavingAmount + totalAmount) * (1 + MONTHLY_INTEREST_RATE);
  20.         System.out.println("After the second month, the account value is " + totalAmount);
  21.         // Calculates third month account value
  22.         totalAmount = (monthlySavingAmount + totalAmount) * (1 + MONTHLY_INTEREST_RATE);
  23.         System.out.println("After the third month, the account value is " + totalAmount);
  24.         // Calculates fourth month account value
  25.         totalAmount = (monthlySavingAmount + totalAmount) * (1 + MONTHLY_INTEREST_RATE);
  26.         System.out.println("After the forth month, the account value is " + totalAmount);
  27.         // Calculates fifth month account value
  28.         totalAmount = (monthlySavingAmount + totalAmount) * (1 + MONTHLY_INTEREST_RATE);
  29.         System.out.println("After the fifth month, the account value is " + totalAmount);
  30.         // Calculates sixth month account value
  31.         totalAmount = (monthlySavingAmount + totalAmount) * (1 + MONTHLY_INTEREST_RATE);
  32.  
  33.         // Displays result
  34.         System.out.println("After the sixth month, the account value is " + totalAmount);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement