Results 1 to 2 of 2

Thread: Please help

  1. #1
    starplayerrob is offline Member
    Join Date
    Apr 2011
    Posts
    37
    Rep Power
    0

    Exclamation Please help

    im trying to creat a java loop program that does the following
    Uses a loop to compute and display, using JOptionPane, the cost of tuition in 15 years at a local university.
    The current cost of tuition is $10, 000.
    Assume that the cost of tuition increases every year by 5%. (Note: declare as a constant)
    Inside your loop please use JOptionPane to write out the year and the tuition cost in a table format for each year. Use DecimalFormat to format output to two decimals.
    Include a routine that computes and displays, using JOptionPane, the total cost of 4 years worth of tuition starting 10 years from now

    i am totally lost i have gotten this so far but im lost and need help getting in the right direction.. if anyone can help me please do asap.

    this is what i have so far but i think i am wrong.. please help

    import java.util.Scanner;
    import java.text.DecimalFormat;

    public class TuitionTruesdell {
    public static void main(String[] args) {

    double tuition = 10000;
    double rate = 1.05;
    double plusTuition = 10000;
    int year = 1;
    String myOutput;
    myOutput = "Year "+" Tuition Amount \n";

    Scanner output = new Scanner(myOutput);
    while(year <= 15){
    tuition = tuition * 1.05 + plusTuition;
    year++;
    myOutput += year + " " + tuition + "\n";

    }
    }
    }

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    To declare a constant value you should create an enum set somewhere in your code,
    it may look like this:

    Java Code:
    public class TuitionTruesdell {
    ...
    private enum TuitionFees {
        UNIVERSITY_FEES(10000,1.05);
        public double fee, increase;
        TuitionFees(double yearlyFee, double yearlyIncrease) {
           fee = yearlyFee;
           increase = yearlyIncrease;
        }
    }
    ...
    }

    To get the information you need, UNIVERSITY_FEES.fee will return 10000
    and UNIVERSITY_FEES.increase will return 1.05

    To calculate a 5% increase for 15 years, the result should be:
    initial fee * increase rate^years; where 'x^y' indicates x to the Power of y.

    You can use Math.pow(double a, double b) in Java to calculate powers
    Math (Java 2 Platform SE v1.4.2)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •