1. Member
Join Date
Oct 2009
Posts
12
Rep Power
0

## 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. 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. Member
Join Date
Oct 2009
Posts
12
Rep Power
0
i tried doing that and I'm still stuck. I guess I'm a total noob...

4. 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!

#### Posting Permissions

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