# calculation

This code can be found in HealthClinic.java. The code bellow is suppose to do the following:

If the status attribute for the patient already refers to this health clinic, he/she is charged a standard fee for a consultation, given by the fee attribute.

If the patient is private, there is no change to their balance attribute.

if the patient is not private, the fee multiplied by the gapPerCent attribute is deducted from their balance. For example, if the fee attribute of the HealthClinic is \$50, and the gapPerCent is 10.0, then the balance attribute of the patient is reduced by \$5.

public void visit(Patient p)
{
if(p.getmedicalFacility()==null)
{
register(p);
}
else
{
if(p.getprivateFund()==true)
{
p.setBalance(p.getBalance() + getFee());
}
else
{
p.setBalance(p.getBalance() + (getFee() * getgapPerCent()));
}

consultation(p);
}
}

Does my code do that?. If no how do I solve the problem.

www.mutaiyas.com/db/Medical.zip

Regards

Eugene
###### Who is Participating?

Commented:
0

Commented:
but your code does it right. maybe you just have inverse balances...
0

Author Commented:
public void visit(Patient p)
{
if(p.getmedicalFacility()==null)
{
register(p);
}
else
{
consultation(p);

if(p.getprivateFund()==true)
{
p.setBalance(p.getBalance())
}
else
{
p.setBalance(p.getBalance() - (getFee() * getgapPerCent()));
}
}
}

public void consulatation(Patient p)
{
p.setBalance(p.getBalance()-getFee());
unregister(p);
}

0

Author Commented:
Is this much better.
0

Author Commented:
I figured it out.

How do I change a negative value to a positive value?
0

Commented:
a=(a<0?-a:a)
0

Commented:
or a=-a, if you want to change positives to negatives, too
0

Author Commented:
p.getBalance()

will return a negative or positive value. If it returns a negative value how do I change it to positive using the method which u have explained.
0

Commented:
just changing nefative to positive looks like random fiddeling in the hope that suddenly your program wil start working.
That is no way to program. Think it through.

A good way ro do that is to do the algorithm on paper, checking at each step 'is this reasonable?'.

On the paper vrite a column of empty lines for each variable:

p_balanca       cost of treatment          hospital 1      hospital 2

--------------     -------------------          -----------      -----------
--------------     -------------------          -----------      -----------

invent a patient with a balance and write it

p_balanca       cost of treatment          hospital 1      hospital 2

5,400.00\$      -------------------          -----------      -----------
--------------     -------------------          -----------      -----------

then send that patient to some hospital with a need for treatment

p_balanca       cost of treatment          hospital 1           hospital 2

5,400.00\$     -------------------          -----------             -----------
--------------              400.00\$            ingrown toenail      -----------

and update the patientbalance as it shoyuld be updated

p_balanca       cost of treatment          hospital 1           hospital 2

5,400.00\$     -------------------          -----------             -----------
400.00\$            ingrown toenail      -----------
5,000.00\$     -------------------          -----------             -----------

etc. this makes it al lot easier to visualize the algorithm, and to check if the code you have vritten do what it should do in each situation.

regards JakobA

0

Author Commented:
boolean negative = (i < 0); so by this can determent if a value is positive or negative.
0

Author Commented:
I also found out about negate() function.
0

Commented:
I hope, you succeed with your program. Is it for a course?
0

Author Commented:
Well Im into asp 3.0 actually. Since im interested to use asp.net, therefore im learning java. Then ill move on to c#.

Regards

Eugene
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.