Answer to Question #111640 in Java | JSP | JSF for Austin

Question #111640
Write a java programme that will compute the future investment at a given rate intereste for specified years.The programme should have a minimum of two classes.
1
Expert's answer
2020-04-24T11:32:57-0400
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Input the investment amount: ");
        double investment = in.nextDouble();
        System.out.print("Input the rate of interest: ");
        double rate = in.nextDouble();
        System.out.print("Input number of years: ");
        int year = in.nextInt();

        rate *= 0.01;

        System.out.println("Years    FutureValue");
        for (int i = 1; i <= year; i++) {
            int formatter = 19;
            if (i >= 10) formatter = 18;
            System.out.printf(i + "%" + formatter + ".2f\n", futureInvestmentValue(investment, rate / 12, i));
        }
    }

    public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years) {
        return investmentAmount * Math.pow(1 + monthlyInterestRate, years * 12);
    }

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS