# Need help will inflation calculator

• February 5th, 2011, 05:31 PM
ciwas01
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;
while (n == numberOfYears){
answer = (cost * rateOfInflation) + cost;
n++;
}

}
}

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.
• January 28th, 2012, 02:52 PM
jordanthillwig
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

....
• January 28th, 2012, 05:09 PM
Norm
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
• January 29th, 2012, 10:39 AM
copeg
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
• January 30th, 2012, 12:37 AM
marylandfour
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;