Need help will inflation calculator
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.
Re: Need help will inflation calculator
I'm sure this is not the most efficient way to do this; but it worked for me and I understand what I did! You're welcome
....
Re: Need help will inflation calculator
@jordanthillwig
Are you doing the OPs homework for him?
Spoonfeeding is discouraged.
http://www.javaprogrammingforums.com...n-feeding.html
Re: Need help will inflation calculator
@jordanthillwig, please read the link Norm provided, and given this is your first post I highly recommend reading the forum rules, amongst which is a clause stating spoonfeeding posts can be edited - which yours has been
Re: Need help will inflation calculator
Quote:
Originally Posted by
ciwas01
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.
Everything looks good to me, except I would look at your method thats actually calculating the inflation.