Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Need help will inflation calculator

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.


  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

    ....
    Last edited by copeg; January 29th, 2012 at 11:38 AM.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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

  4. The Following User Says Thank You to Norm For This Useful Post:

    copeg (January 29th, 2012)

  5. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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

  6. #5
    Junior Member
    Join Date
    Jan 2012
    Posts
    11
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: Need help will inflation calculator

    Quote Originally Posted by ciwas01 View Post
    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.

Similar Threads

  1. Calculator
    By javapenguin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 22nd, 2010, 09:00 AM
  2. [SOLVED] Another Calculator Problem
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 4th, 2010, 03:31 PM
  3. [SOLVED] Calculator help
    By Bradshjo in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 1st, 2010, 04:27 PM
  4. Calculator help.
    By Skinnyskinny in forum Java Theory & Questions
    Replies: 6
    Last Post: August 1st, 2009, 12:34 PM
  5. Problem of implementing mathematic logic in Java applet
    By AnithaBabu1 in forum Java Applets
    Replies: 0
    Last Post: August 15th, 2008, 11:42 PM