Write an inflation calculator. Input should be amount, rate of inflation and num
ID: 3541441 • Letter: W
Question
Write an inflation calculator. Input should be amount, rate of inflation and number of years. Output should be the future value of the amount.
not sure if my counter or my math is wrong but its not giving the correct output.. heres the code
codes must be in java please.
thank you
import java.io.InputStream;
import java.util.Scanner;
public class Assignment2Part1 {
public static void main(String[] args)
{
int cCost, nYears;
double per, per2 = 0, iCost = 0, amount = 0;
System.out.println("Enter the current cost of the item: ");
Scanner keyboard1 = new Scanner(System.in);
cCost = keyboard1.nextInt();
System.out.println("Enter the expected inflation rate per year "
+ "(enter as a percentage and do not include the percent sign); ");
Scanner keyboard2 = new Scanner(System.in);
per = keyboard2.nextFloat();
System.out.println("Enter the whole number of years in the future to project cost: ");
Scanner keyboard3 = new Scanner(System.in);
nYears = keyboard3.nextInt();
per2 = (per / 100);
int a = nYears;
iCost = (cCost * per2);
double c = (iCost + cCost);
amount = c ;
for (int i = 0; i < a; i++)
{
iCost = (amount * per2);
c = (iCost + amount);
amount = c ;
}
System.out.println(cCost);
System.out.println(per);
System.out.println(nYears);
System.out.println(per2);
System.out.println(iCost);
System.out.println(amount);
}
}
also if you can
Write a counter class in its own file. That will allow the counter to be used by any program.
. Include an override of the default constructor that sets the counter to zero and a constructor that allows you to set the count.
ex
This program creates and uses Counters
Initial state
counter1 is at 0
counter2 is at 0.
counter1 equals counter2.
Error - Attempted to subtract 1 widget from 0 widgets.
Number of widgets reset to 0.
State after first test
counter1 is at 5.
counter2 is at 1.
counter1 does not equal counter2.
State after second test
counter1 is at 6.
counter2 is at 6.
counter1 equals counter2.
Process completed.
Explanation / Answer
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.