In java how do you write an inflation calculator. Input should be amount, rate of inflation and number of years. Output should be the future value of the amount.
Example Output:
Enter the current cost of the item: 1000
Enter the expected inflation rate per year
(Enter as a percentage and do not include the percent sign): 6
Enter the whole number of years in the future to project cost: 10
At 6.00% inflation per year, the cost in 10 year(s) will be $1,790.85.
Process completed
import java.util.Scanner; public class Inflation { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter the current cost of the item: "); double value = in.nextDouble(); System.out.println("Enter the expected inflation rate per year"); System.out.print("(Enter as a percentage and do not include the percent sign): "); double rate = in.nextDouble(); System.out.print("Enter the whole number of years in the future to project cost: "); int numYears = in.nextInt(); double finalValue = Math.pow(1 + rate / 100, numYears) * value; System.out.printf("At %.2f%% inflation per year, the cost in %d year(s) will be $%,.2f.\n", rate, numYears, finalValue); System.out.println("Process completed"); } }
Get Answers For Free
Most questions answered within 1 hours.