Hello, I need at create an inflation calculator that should execute as follows:
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.
So far my code looks like this:
InflationCalculator.java:
import java.util.Scanner;
class InflationCalculator {
public static void main(String[] args){
Scanner keyboard = new Scanner (System.in);
RateOfInflation rateObject = new RateOfInflation();
int cost, numberOfYears;
double rateOfInflation;
System.out.print("Enter the current cost of the item:");
cost = keyboard.nextInt();
System.out.println("Enter the expected inflation rate per year");
System.out.print("(Enter as a percentage and do not include the percent sign
");
rateOfInflation = (keyboard.nextInt() * .01);
System.out.print("Enter the whole number of years in the future to project cost:");
numberOfYears = keyboard.nextInt();
rateObject.calcMethod(cost, numberOfYears, rateOfInflation);
}
}
and
RateOfInflation.java
public class RateOfInflation {
public double calcMethod(int cost, int numberOfYears, double rateOfInflation){
int n = 0;
double answer;
while (n == numberOfYears){
answer = (cost * rateOfInflation) + cost;
n++;
System.out.println( answer );
}
}
}
Not even sure if I have the right approach at this, been reading java for the past couple weeks and its driving me crazy. Thanks for any help that can be provided.