Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help getting started designing and creating a program that calculates sim

ID: 3560456 • Letter: I

Question

I need help getting started designing and creating a program that calculates simple and compound interest. Simple interest in this case means that interest is only applied to the original amount. For instance, if a person deposits $1000 at 10% annual interest, then after one year they would have $1100 (the original $1000 plus the $100 interest) and after two years they would have $1200 (the original $1000, plus the $100 earned the first year, plus the $100 earned the second year).
With compound interest, the interest is applied to all money earned. So, starting with $1000 at 10% annual interest, after one year the user would have $1100 (the original amount plus $100 interest) and after two years the user would have $1210 (the $1100 they started with at the beginning of the year plus the $110 interest).
The requirements of this program are:

Explanation / Answer

import java.util.Scanner;
import java.text.*;
class CompoundInterest {
  static double a, p, r, t, compoundInterest;
  static double _72Rule_yearsToDoublePrincipal;
  static double _72Rule_interestToDoublePrincipal;
  static double currentValue;
  static int n;
  public static void main(String[] args) {
    // Create decimal format that rounds off to two decimal places
    DecimalFormat df = new DecimalFormat("##.##");
    // Create Scanner object for User input
    Scanner input = new Scanner(System.in);

    /* User to input values needed to:
     * 1. Work out how long to double investment using rule 72
     * Rule 72 states that 72 / r where r = interest rate
     * For example: If interest rate were 6%, then it would
     * take (72/6) = 12 years to double your investment, or if
     * you wish to double your investment within 10 years, then:
     * 72 / t where t = years which gives in this example:
     * (72/10) = 7.2% interest rate required to achive this.
     *
     * 2. Work out the Compound interest earned in that time, using the formula:
     * a = p(1 + r/n) ^ nt where:
     * a = final amount earnt
     * p = principal amount (your initial investment)
     * r = Annual interest rate represented as a DECIMAL not as a percentage!!!
     * That is to say if interest was 6% then r = 6/100 = 0.06
     * n = number of times interest is compounded per year
     * t = number of years amount is invested
     */
    System.out.println("---------"
      + "-----------------------------");
    System.out.println("Please Enter the following information");
    System.out.println("---------"
      + "-----------------------------");
    System.out.println();
    System.out.println("How much money will you be investing? "
            + "How many years would you like to double it in? "
            + "What interest rate would you like? "
            + "How often will your principal receive compound interest: "
            + "Monthly [12], Bi-annually [2]), Quarterly [4]?");

    p = input.nextDouble();
    t = input.nextDouble();
    r = input.nextDouble()/100;
    n = input.nextInt();

    _72Rule_yearsToDoublePrincipal = 72/(r * 100);
    _72Rule_interestToDoublePrincipal
        = 72/_72Rule_yearsToDoublePrincipal;

    System.out.println();
    System.out.println("To double your investment of $" + df.format(p)
      + " will take "
      + df.format(
        _72Rule_yearsToDoublePrincipal
            ) + " years");

    a = p * Math.pow((1 + (r/n)), (n * t));

    currentValue = _72Rule_yearsToDoublePrincipal * a;

    compoundInterest = currentValue - p;

    System.out.println();
    System.out.println("You earned in this time $" + df.format(compoundInterest));
    System.out.println();
    System.out.println("Your current investment is now worth $"
      + df.format(currentValue));
  }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote