Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that takes two numbers from the Java console representing, respectively, an investment and an interest rate (you will expect the user to

Write a program that takes two numbers from the Java console representing, respectively, an investment and an interest rate (you will expect the user to enter a number such as .065 for the interest rate, representing a 6.5% interest rate). Your program should calculate and output (in $ notation) the future value of the investment in 5, 10, and 20 years using the following formula: future value = investment * (1 + interest rate)year We will assume that the interest rate is an annual rate and is compounded annually.

This is what I have so far- the program runs just fine I'm just having a hard time figuring out how to convert the future value into US dollars. Right now I'm getting back a long scientific number, so please help me figure out how to convert :)

import java.util.*; public class calculate { public static double getFutureValue(int investment,double interestRate,int year) { return Math.pow(investment*(1+interestRate),year); } public static void main(String[] args) { int investment; double dollars; double interestRate; Scanner keyboard = new Scanner(System.in); System.out.println("Enter the investment > "); investment = keyboard.nextInt(); System.out.println("Enter the interest rate > " ); interestRate = keyboard.nextDouble(); System.out.println("With an investment of $"+investment); System.out.println("at an interest rate of "+interestRate+"% compounded annually:"); double futureValue = getFutureValue(investment,interestRate,5); System.out.println("The future value after 5 years is : "+futureValue); futureValue = getFutureValue(investment,interestRate,10); System.out.println("The future value after 10 years is : "+futureValue); futureValue = getFutureValue(investment,interestRate,20); System.out.println("The future value after 20 years is : "+futureValue);

} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

Question What are the advantages of a written bonus plan?

Answered: 1 week ago