Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

DESCRIPTION

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.)

Do not prompt anything from the user before reading in the investment and interest rate. Your program should calculate and output (in $ notation) the future value of the investment in 5, 10, 15 and 20 years using the following formula:

future value = investment * (1 + interest rate)^year

We will assume the interest rate is an annual rate and is compounded annually.

Use NumberFormat to output the $:

https://docs.oracle.com/javase/7/docs/api/javax/swing/text/NumberFormatter.html

Only display the output like this:

Year 5: $31,907.04

Year 10: $40,722.37

Year 15: $51,973.20

Year 20: $66,332.44

substituting the correct amount for the value of the investment after the given period.

The program must ignore any input other than decimal numbers. Scanner s = new

Scanner(System.in); while(!s.hasNextDouble()) s.next(); Lastly, don't forget to take out the package when you submit to mimir. Pay attention to the spacing in the output.

this is what the professor give me .

package interestrate;

import java.util.Scanner; import javax.swing.text.NumberFormatter; import java.text.NumberFormat; import java.util.Locale;

/** * * @author dfreer */ public class InterestRate {

/** * @param args the command line arguments */ public static void main(String[] args) { NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US); Scanner s = new Scanner(System.in); //fill in the logic here //Display like this exactly System.out.println("Year " + + ": " + nf.format()); } }

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

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions