Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

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.

You can download the latest code from:

www.mutaiyas.com/db/Medical.zip

Your help is kindly appreciated.

Regards

Eugene
0
eugene007
Asked:
eugene007
  • 7
  • 5
2 Solutions
 
Mig-OCommented:
add - instead of +
0
 
Mig-OCommented:
but your code does it right. maybe you just have inverse balances...
0
 
eugene007Author 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
eugene007Author Commented:
Is this much better.
0
 
eugene007Author Commented:
I figured it out.

How do I change a negative value to a positive value?
0
 
Mig-OCommented:
a=(a<0?-a:a)
0
 
Mig-OCommented:
or a=-a, if you want to change positives to negatives, too
0
 
eugene007Author 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
 
JakobACommented:
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
 
eugene007Author Commented:
boolean negative = (i < 0); so by this can determent if a value is positive or negative.
0
 
eugene007Author Commented:
I also found out about negate() function.
0
 
Mig-OCommented:
I hope, you succeed with your program. Is it for a course?
0
 
eugene007Author 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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now