Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java, write a program that deals with inflation, which is essentially the rising cost of general goods over time. That is, the price of

In Java, write a program that deals with inflation, which is essentially the rising cost of general goods over time. That is, the price of goods, such as a packet of peanuts, goes up as time goes by. So, you will write a program to gauge the expected cost of an item in a specified number of years. The program asks for the cost of the item, the number of years, and the rate of inflation. The output is the estimated cost of the item after that number of years, using the given inflation rate. The user enters the inflation rate as a percentage, for example 4.5. You will have to convert the percentage to a fraction (like 0.045), and then use a loop to estimate the item's price adjusted for inflation. Note that this is similar to computing compound interest on a credit card account or a mortgage. Also note that you must check each of the values provided by the user to make sure that they are reasonable. Finally, you have to print out the price with exactly two places after the decimal (for the cents) after your calculations are done

To adjust the price for inflation, you need to increase the price by the inflation rate each year. For example, if you have an item that is initially $10, with inflation rate of 10%, the adjusted prices will be:

After 1 year: $10.00 (1 + 0.10) = $11.00

After 2 years: $11.00 (1 + 0.10) = $12.10

After 3 years: $12.10 (1 + 0.10) = $13.31

In other words, to calculate the price after another year, you have to use the value from the current year, NOT the original price. To do this, you must use a loop. An example of what your program should output:

Enter the current price of the item: $10

Enter the number of years: 3

Enter the inflation rate as a percentage: 10

After 3 years, the price will be $13.31

You have been supplied JUnit tests for some simple valid examples, as well as negative price, negative year, and negative interest rate.

If the price input is negative, the output should be: The current price must be at least 0!

If the year input is negative, the output should be: The number of years must be at least 0!

If the inflation rate is negative, the output should be: The inflation rate must be at least 0!

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

More Books

Students also viewed these Databases questions

Question

1. How do most insects respire ?

Answered: 1 week ago

Question

Who is known as the father of the indian constitution?

Answered: 1 week ago

Question

1.explain evaporation ?

Answered: 1 week ago

Question

Understand the role of internal marketing and communications.

Answered: 1 week ago