Results 1 to 4 of 4

Thread: Student class

  1. #1
    Java_Fanatic is offline Member
    Join Date
    Oct 2009
    Posts
    12
    Rep Power
    0

    Default Student class

    I have a problem and i just need a little help with it. The purpose of this portion of the code is to determine how much the cost of healthcare will be for a student. The healthcare system works like this:

    For the first 10 credits, the price is $25 per credit. For the next 5 credits, the price is $20 per credit added on to the price before. For 15 or more credits, the price is $15 per credit added on to the price before as well.

    I have this much code so far:

    if(credit <= 10)
    hCare = 25 * credit;
    else if(credit >= 10 && credit <= 15)
    hCare = 20 * credit;
    else if(credit > 15)
    hCare = 12 * credit;

    I get it to add each credit but i need it to add the previous hCare value where hCare is a private double. Can somebody help me???

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    The logic is simply how you would solve this on paper. Do that, and the code will follow quite easily. I'm dead serious here.

  3. #3
    Java_Fanatic is offline Member
    Join Date
    Oct 2009
    Posts
    12
    Rep Power
    0

    Default

    i tried doing that and I'm still stuck. I guess I'm a total noob...

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    One way, use a for loop to loop through each credit and add to a total cost variable an amount depending on the current index value of the loop.

    Another way, if credits > 10, figure out how much the first 10 credits add to cost and add that to total, then add the others based on the formula...

    This really isn't a Java question, or even much of a math question, but more of a basic sit and think question. You can do it!

Similar Threads

  1. New java student needs help
    By cmizer in forum New To Java
    Replies: 9
    Last Post: 12-13-2008, 07:16 AM
  2. Student--begginer--help!!!
    By AmandaIT in forum New To Java
    Replies: 6
    Last Post: 05-09-2008, 04:37 AM
  3. Student Help
    By mattwaab in forum Java Applets
    Replies: 0
    Last Post: 02-08-2008, 06:31 PM
  4. help student
    By jvasilj1 in forum New To Java
    Replies: 15
    Last Post: 02-02-2008, 09:23 AM
  5. please help a student
    By jvasilj1 in forum New To Java
    Replies: 0
    Last Post: 02-01-2008, 02:11 AM

Posting Permissions

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