Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 2nd, 2005, 9:58 AM   #1
solomon_13000
Newbie
 
Join Date: Apr 2005
Posts: 5
Rep Power: 0 solomon_13000 is on a distinguished road
function

Patient class has the following attribute and method

name: string
recordNo: int
privateFun: boolean
balance: double
status: MedicalFacility

present()


MedicalFacility class has the following attribute and method.
Medical Facility class is an abstract class.

name: string

<<abstract>> visit()


Hospital class is a class that extends from the MedicalFacility abstract class and has the following attribute and method.

probAdmit: double

visit()
triage()
admit()
discharge()


HealthClinic class is a class that extends from the MedicalFacility abstract class and has the following attribute and method.

fee: double
gapPerCent: double

visit()
register()
unregister()
consultation()


Procedure class has the following attribute and method.

name: string
code:int
description: string
elective: boolean
cost: double

perform()



Relationship:

HealthService is link to MedicalFacility class by a 1 to * relationship.

HealthService is link to Patient class by a 1 to * relationship.

Hospital class is link to the procedure class by 1 to * relationship.


This is how my classes look like. Im using Vector. Hope this help




This is the code I am having problems with

public static void operate()
{
System.out.println("Enter the patients no");
int pno = SavitchIn.readLineInt();
Patient p = hs.searchPatient(pno);

if(p==null)
{
System.out.println("The patient is invalid");
}

MedicalFacility m = p.getmedicalFacility();

if(m==null)
{
System.out.println("The patient has not been admited to a hospital");
}

if(m instanceof Hospital)
{
System.out.println("The procedure can be performed");
}

String name = ((Hospital)m).getName();
MedicalFacility medf = hs.searchFacility(name);


System.out.println("Enter the procedure code");
int code = SavitchIn.readLineInt();
Procedure pr = ((Hospital)medf).search(code);

if(pr==null)
{
System.out.println("The procedure is invalid");
}

pr.perform(p);
}



The code bellow is invoked from the driver program, MedicalConsole.java.

public void perform(Patient p)
{
if (p.getmedicalFacility() instanceof Hospital)
{
if(p.getprivateFund()==true && getElective()==true)
{
setCost(2000);
}

if(p.getprivateFund()==true && getElective()==false)
{
setCost(1000);
}

if(p.getprivateFund()==false && getElective()==true)
{
setCost(getCost());
}

if(p.getprivateFund()==false && getElective()==false)
{
setCost(0.00);
}

p.setBalance(p.getBalance()+getCost());

((Hospital)p.getmedicalFacility()).triage(p);

}
}





This is my explanation on how the operate will work.

OPERATE

The user is prompted to enter a hospital, a patient, and an identifier for the procedure to be performed on the patient.

The procedure is "performed" as long as the patient has previously been admitted to the hospital (the status attribute of the Patient refers to the Hospital object).

Otherwise the program should display a suitable message. The cost of the procedure is determined by the privateFund attribute of Patient, and the elective and cost attributes of Procedure, according to the table below:

Patient: Private
Procedure: elective
amount charged: $2000

Patient: private
Procedure: not elective
amount charged: $1000

Patient: not private
Procedure: elective
amount charged: cost

Patient: not private
Procedure: not elective
amount charged: elective

The amount charged in the table above is subtracted from the balance attribute of the Patient. The triage() method is called again to determine (at random) if the patient should remain in the hospital. If the random number is less than the probAdmit value, then the discharge() method is called, and the patient is discharged by setting the status attribute to null. Otherwise, the patient remains in hospital, and an additional procedure may be performed by selecting the Operate option again for the same patient.



Remarks: The main problem I am facing is that the balance is always 0.00. It never change. If you would like to see the application, I can send it to you.


Regards

Eugene
solomon_13000 is offline   Reply With Quote
Old Apr 2nd, 2005, 3:27 PM   #2
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4 mackenga is on a distinguished road
Well, without the rest of the code it's not so easy to say, but it does look like you set the balance using p.setBalance(), so I'd check that method for an error first. If you're sure that's fine, check to make sure getCost() and setCost() are looking at the same variable; a likely cause of this sort of problem behaviour would be either one of these procedures using a local variable with the same name as the variable that's a member of the class and supposed to be shared between them. Look for declarations of the balance variable inside either of these methods; they shouldn't be there.

That's all I can think of.
mackenga is offline   Reply With Quote
Old Apr 2nd, 2005, 10:04 PM   #3
solomon_13000
Newbie
 
Join Date: Apr 2005
Posts: 5
Rep Power: 0 solomon_13000 is on a distinguished road
Am I allowed to specify a link, whereby you can download the .java files for my application?.
solomon_13000 is offline   Reply With Quote
Old Apr 2nd, 2005, 10:08 PM   #4
solomon_13000
Newbie
 
Join Date: Apr 2005
Posts: 5
Rep Power: 0 solomon_13000 is on a distinguished road
The codes to my program.

HealthClinic.java

import java.util.*;

public class HealthClinic extends MedicalFacility
{
private double fee;
private double gapPerCent;
private Vector procedures;

public HealthClinic(String inname, double infee, double ingappercent)
{
super(inname);
setFee(infee);
setgapPerCent(ingappercent);
setProcedures();
}

public void setFee(double infee)
{
fee = infee;
}

public void setgapPerCent(double ingappercent)
{
gapPerCent = ingappercent;
}

public double getFee()
{
return fee;
}

public double getgapPerCent()
{
return gapPerCent/100;
}

public void setProcedures()
{
if(procedures==null)
procedures = new Vector();
}

public Vector getProcedures()
{
return procedures;
}

public void add(Procedure p)
{
getProcedures().add(p);
}

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);
}
}

public void register(Patient p)
{
p.setmedicalFacility(this);
}

public void unregister(Patient p)
{
p.setmedicalFacility(null);
}

public void consultation(Patient p)
{
unregister(p);
}

public String toString()
{
return super.toString() + " with a fee of " + getFee() + " and gapPerCent of " + getgapPerCent();
}
}



HealthService.java


import java.util.*;

public class HealthService
{
private String name;
private Vector patients;
private Vector medicalfacilities;

public HealthService()
{
setName("Health");
setPatients();
setmedicalFacilities();
}

public void setName(String inname)
{
name = inname;
}

public String getName()
{
return name;
}

public void setPatients()
{
if(patients==null)
patients = new Vector();
}

public void setmedicalFacilities()
{
if(medicalfacilities==null)
medicalfacilities = new Vector();
}

public Vector getPatients()
{
return patients;
}

public Vector getmedicalFacilities()
{
return medicalfacilities;
}

public void add(Patient p)
{
getPatients().add(p);
}

public void add(MedicalFacility m)
{
getmedicalFacilities().add(m);
}


public Patient searchPatient(int inrecordno)
{
Iterator iter = getPatients().iterator();

while(iter.hasNext())
{
Patient m = (Patient)iter.next();

if(m.getrecordNo()==inrecordno)
{
return m;
}
}

return null;
}


public MedicalFacility searchFacility(String inname)
{
Iterator iter = getmedicalFacilities().iterator();

while(iter.hasNext())
{
MedicalFacility m = (MedicalFacility)iter.next();

if(m.getName().equalsIgnoreCase(inname))
{
return m;
}
}

return null;
}
}



Hospital.java


import java.util.*;

public class Hospital extends MedicalFacility
{
public double probAdmid;
private Vector procedures;

public Hospital(String inname, double inprobadmid)
{
super(inname);
setprobAdmid(inprobadmid);
setProcedures();
}

public void setprobAdmid(double inprobadmid)
{
probAdmid = inprobadmid;
}

public double getprobAdmid()
{
return probAdmid;
}

public void setProcedures()
{
if(procedures==null)
procedures = new Vector();
}

public Vector getProcedures()
{
return procedures;
}

public void add(Procedure p)
{
getProcedures().add(p);
}

public void visit(Patient p)
{
triage(p);
}

public void triage(Patient p)
{
double r = Math.random();

if(r > probAdmid)
{
admit(p);
}
else
{
discharge(p);
}

}

public void admit(Patient p)
{
p.setmedicalFacility(this);
}

public void discharge(Patient p)
{
p.setmedicalFacility(null);
}

public Procedure search(int code)
{
Iterator iter = getProcedures().iterator();

while(iter.hasNext())
{
Procedure p = (Procedure) iter.next();

if(p. getCode() == code)
{
return p;
}
}

return null;
}

public String toString()
{
return super.toString() + " with probAdmit " + getprobAdmid();
}
}



MedicalConsole.java[/u]


import java.util.*;

public class MedicalConsole
{
private static HealthService hs;

public static void main(String[] args)
{
System.out.println("\n - HEALTH SERVICE MANAGEMENT SYSTEM -\n");

hs = new HealthService();

while(true)
{
menu();
}
}

public static void menu()
{

System.out.println("\n");
System.out.println("____________________________________________________");
System.out.println(" MAIN MENU ");
System.out.println("Please choose a number from the menu and ");
System.out.println("press <ENTER> ");
System.out.println("| |");
System.out.println("1. Add ");
System.out.println("2. Delete ");
System.out.println("3. List ");
System.out.println("4. Present ");
System.out.println("5. Operate ");
System.out.println("6. Exit ");
System.out.println("\n");

System.out.println("Please type your selection then press <ENTER>: ");
int s = SavitchIn.readInt();
switchmenu(s);
}

public static void addsubmenu()
{

System.out.println("\n");
System.out.println("____________________________________________________");
System.out.println(" ADD SUB MENU ");
System.out.println("Please choose a number from the menu and ");
System.out.println("press <ENTER> ");
System.out.println("| |");
System.out.println("1. Add Medical Facility ");
System.out.println("2. Add Patient ");
System.out.println("3. Add Procedure ");
System.out.println("\n");

System.out.println("Please type your selection then press <ENTER>: ");
int s = SavitchIn.readInt();
switchaddsubmenu(s);
}

public static void listsubmenu()
{

System.out.println("\n");
System.out.println("____________________________________________________");
System.out.println(" LIST SUB MENU ");
System.out.println("Please choose a number from the menu and ");
System.out.println("press <ENTER> ");
System.out.println("| |");
System.out.println("1. list Medical Facility ");
System.out.println("2. list Patient ");
System.out.println("3. list Procedure ");
System.out.println("\n");

System.out.println("Please type your selection then press <ENTER>: ");
int s = SavitchIn.readInt();
switchlistsubmenu(s);
}

public static void switchmenu(int s)
{

switch(s)
{
case 1:
addsubmenu();
break;

case 2:
break;

case 3:
listsubmenu();
break;

case 4:
present();
break;

case 5:
operate();
break;

case 6:
System.out.println("\nYou choose to exit. Do you really want to exit (y/n)?: ");
String sExit = SavitchIn.readLine();
sExit = sExit.trim();

if(sExit.equals("y"))
{
System.out.println("\n\n************************************");
System.out.println("Thank you! Have a nice day!!");
System.out.println("************************************\n\n");
System.exit(0);
}

if(sExit.equals("n"))
{
menu();
}
else
{
System.out.println("\tINVALID OPTION. Please type y or n.");
menu();
}

default:
System.out.println("\n\n************************************");
System.out.println("Invalid Integer. Please try again.");
System.out.println("************************************\n\n");
menu();
}

}


public static void switchaddsubmenu(int s)
{

switch(s)
{
case 1:
addMedicalFacility();
break;

case 2:
addPatient();
break;

case 3:
addProcedure();
break;


default:
System.out.println("\n\n************************************");
System.out.println("Invalid Integer. Please try again.");
System.out.println("************************************\n\n");
menu();
}

}


public static void switchlistsubmenu(int s)
{

switch(s)
{
case 1:
listMedicalFacility();
break;

case 2:
listPatient();
break;

case 3:
listProcedure();
break;


default:
System.out.println("\n\n************************************");
System.out.println("Invalid Integer. Please try again.");
System.out.println("************************************\n\n");
menu();
}

}

public static void addMedicalFacility()
{
MedicalFacility m = null;

System.out.println("Please enter the name");
String name = SavitchIn.readLine();

System.out.println("Select hospital or health clinic (h/c)");
char medtype = SavitchIn.readLineNonwhiteChar();

if(medtype == 'h' || medtype=='H')
{
System.out.println("Enter the probAdmid");
double probAdmit = SavitchIn.readLineDouble();
m = new Hospital(name,probAdmit);
}
else
{
System.out.println("Enter the fee");
double fee = SavitchIn.readLineDouble();
System.out.println("Enter the gapPerCent");
double gap = SavitchIn.readLineDouble();
m = new HealthClinic(name,fee,gap);
}

hs.add(m);
}


public static void addPatient()
{
Patient p = null;

System.out.println("Enter the name");
String name = SavitchIn.readLine();
System.out.println("Enter the type");
String type = SavitchIn.readLine();

p = new Patient(name,type);

hs.add(p);
}


public static void addProcedure()
{

System.out.println("Enter the name of the medical facility");
String medf = SavitchIn.readLine();
MedicalFacility m = hs.searchFacility(medf);

if(m==null)
{
System.out.println("The medical facility is not valid");
}
else
{
System.out.println("Enter the name");
String name = SavitchIn.readLine();
System.out.println("Enter the code");
int code = SavitchIn.readLineInt();
System.out.println("Enter the description");
String description = SavitchIn.readLine();
System.out.println("Enter the elective");
String elec = SavitchIn.readLine();
System.out.println("Enter the cost");
double cost = SavitchIn.readLineDouble();

Procedure p = new Procedure(name,code,description,elec,cost);

((Hospital)m).add(p);
}

}

public static void listMedicalFacility()
{
Vector mf = hs.getmedicalFacilities();
Iterator iter = mf.iterator();

while(iter.hasNext())
{
Object o = iter.next();

if(o instanceof Hospital)
{
Hospital h = (Hospital) o;
System.out.println(h);
}

if(o instanceof HealthClinic)
{
HealthClinic c = (HealthClinic) o;
System.out.println(c);
}
}
}

public static void listPatient()
{
Vector pt = hs.getPatients();
Iterator iter = pt.iterator();

while(iter.hasNext())
{
Patient p = (Patient) iter.next();
System.out.println(p);
}
}

public static void listProcedure()
{
Vector mf = hs.getmedicalFacilities();
Iterator iter1 = mf.iterator();

while(iter1.hasNext())
{
Object o = iter1.next();

if(o instanceof Hospital)
{
Hospital h = (Hospital) o;

Vector pr = h.getProcedures();
Iterator iter2 = pr.iterator();

while(iter2.hasNext())
{
Procedure p = (Procedure) iter2.next();
System.out.println(p);
}
}
}
}


public static void present()
{
System.out.println("Enter the patient record no");
int pno = SavitchIn.readLineInt();
Patient p = hs.searchPatient(pno);

if(p==null)
{
System.out.println("The patient is not valid");
}

System.out.println("Enter the medical facility name");
String mname = SavitchIn.readLine();
MedicalFacility m = hs.searchFacility(mname);

if(m==null)
{
System.out.println("The medical facility is not valid");
}

p.present(m);
}

public static void operate()
{
System.out.println("Enter the patients no");
int pno = SavitchIn.readLineInt();
Patient p = hs.searchPatient(pno);

if(p==null)
{
System.out.println("The patient is invalid");
}

MedicalFacility m = p.getmedicalFacility();

if(m==null)
{
System.out.println("The patient has not been admited to a hospital");
}

if(m instanceof Hospital)
{

String name = ((Hospital)m).getName();
MedicalFacility medf = hs.searchFacility(name);


System.out.println("Enter the procedure code");
int code = SavitchIn.readLineInt();
Procedure pr = ((Hospital)medf).search(code);

if(pr==null)
{
System.out.println("The procedure is invalid");
}

pr.perform(p);
}
}
}



MedicalFacility.java


public abstract class MedicalFacility
{
public String name;

public MedicalFacility(String inname)
{
setName(inname);
}

public void setName(String inname)
{
name = inname;
}

public String getName()
{
return name;
}

public abstract void visit(Patient p);

public String toString()
{
return getName() + " Medical Facility ";
}

}



Patient.java


public class Patient
{
private String name;
private int recordNo;
private boolean privateFund;
private double balance;
private MedicalFacility status;
private static int ms_recordNumber = 1000;


public Patient(String inname, String inprivatefund)
{
setName(inname);
setprivateFund(inprivatefund);
setBalance(0.00);
setrecordNo();
setmedicalFacility(null);
}

public void setName(String inname)
{
name = inname;
}

public void setprivateFund(String inprivatefund)
{
if(inprivatefund=="private")
{
privateFund = true;
}

if(inprivatefund=="non private")
{
privateFund = false;
}
}

public void setBalance(double inbalance)
{
balance = inbalance;
}


public void setrecordNo()
{
recordNo = getrecordNumber();
}

public void setmedicalFacility(MedicalFacility instatus)
{
status = instatus;
}

public String getName()
{
return name;
}

private synchronized static int getrecordNumber()
{
return ++ms_recordNumber;
}

public int getrecordNo()
{
return recordNo;
}

public boolean getprivateFund()
{
return privateFund;
}

public double getBalance()
{
return balance;
}

public MedicalFacility getmedicalFacility()
{
return status;
}

public void present(MedicalFacility m)
{
if(m instanceof Hospital)
{
((Hospital)m).visit(this);
}
else
{
((HealthClinic)m).visit(this);
}
}

public String toString()
{
return "Patient " + getName() + " with a record number " + getrecordNo() + " has a balance of " + getBalance();
}
}



Procedure.java


public class Procedure
{
private String name;
private int code;
private String description;
private boolean elective;
private double cost;

public Procedure(String inname, int incode, String indescription, String inelective, double incost)
{
setName(inname);
setCode(incode);
setDescription(indescription);
setElective(inelective);
setCost(incost);
}

public void setName(String inname)
{
name = inname;
}

public void setCode(int incode)
{
code = incode;
}

public void setDescription(String indescription)
{
description = indescription;
}

public void setElective(String inelective)
{
if(inelective == "elective")
{
elective = true;
}

if(inelective == "not elective")
{
elective = false;
}
}

public void setCost(double incost)
{
cost = incost;
}

public String getName()
{
return name;
}

public int getCode()
{
return code;
}

public String getDescription()
{
return description;
}

public boolean getElective()
{
return elective;
}

public double getCost()
{
return cost;
}

public void perform(Patient p)
{
if (p.getmedicalFacility() instanceof Hospital)
{

if(p.getprivateFund()==true && getElective()==true)
{
setCost(2000);
}

if(p.getprivateFund()==true && getElective()==false)
{
setCost(1000);
}

if(p.getprivateFund()==false && getElective()==true)
{
setCost(getCost());
}

if(p.getprivateFund()==false && getElective()==false)
{
setCost(0.00);
}

p.setBalance(p.getBalance()+getCost());

((Hospital)p.getmedicalFacility()).triage(p);

}
}

public String toString()
{
return "Procedure " + getName() + " with the code " + getCode() + " and desciption " + getDescription() + " and cost " + getCost();
}
}
solomon_13000 is offline   Reply With Quote
Old Apr 2nd, 2005, 10:11 PM   #5
solomon_13000
Newbie
 
Join Date: Apr 2005
Posts: 5
Rep Power: 0 solomon_13000 is on a distinguished road
complete explanation on how my application work

MedicalConsole is the name of the driver program.

The application comes with 5 menu operations.

ADD

Add - allow the user to create an object to represent a medical facility (hospital or health clinic), a patient, or a procedure.

If the user chooses to add a medical facility, the user must choose between a hospital or health clinic.

The probAdmit attribute represents the probability that a patient will be admitted, and must be set by the user to a value between 0 and 1.

If the user wishes to create a patient object, the status attribute should be set to null to indicate that the patient is not currently admitted to any hospital, and is not registered at any health clinic.

The recordNo attribute should be automatically generated, and the balance should be set to zero. The other attributes are entered by the user.

If the user wishes to create a procedure object, a hospital must be chosen to add the procedure to. If there are no hospitals, the program must prompt the user to add one, then return to adding the procedure details.


LIST

Allow the user to choose which type of object to list, then display all attributes, indicate the type, for example, whether a medical facility is a hospital or health clinic.



PRESENT

Simulate a patient presenting at a medical facility. Your program must provide an option to choose a patient and a hospital or a health clinic, and check for valid entries. At this point the visit() method is called, but has different functionality depending on the type of medical facility.

If the patient presents at a health clinic, the program must check the status attribute for the patient.

If the status does not contain a reference to this health clinic, he/she is registered by setting the status attribute to refer to this health clinic, but cannot have a consultation until the next visit.

At this point, display a message to inform the user that the patient has made an appointment. There is no charge for registration.

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.

However, 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.

If the patient presents at a hospital, the triage() method is called. A random number generator is used to determine whether the patient will be admitted, according to the setting of probAdmit. For example, if probAdmit = 0.5, and a random number generated (between 0 and 1) is 0.6, then the patient is admitted by setting the status attribute to refer to this hospital.




OPERATE

The user is prompted to enter a hospital, a patient, and an identifier for the procedure to be performed on the patient.

The procedure is "performed" as long as the patient has previously been admitted to the hospital (the status attribute of the Patient refers to the Hospital object).

Otherwise the program should display a suitable message. The cost of the procedure is determined by the privateFund attribute of Patient, and the elective and cost attributes of Procedure, according to the table below:

Patient: Private
Procedure: elective
amount charged: $2000

Patient: private
Procedure: not elective
amount charged: $1000

Patient: not private
Procedure: elective
amount charged: cost

Patient: not private
Procedure: not elective
amount charged: elective

The amount charged in the table above is subtracted from the balance attribute of the Patient. The triage() method is called again to determine (at random) if the patient should remain in the hospital. If the random number is less than the probAdmit value, then the discharge() method is called, and the patient is discharged by setting the status attribute to null. Otherwise, the patient remains in hospital, and an additional procedure may be performed by selecting the Operate option again for the same patient.


QUIT

Quit the program.
solomon_13000 is offline   Reply With Quote
Old Apr 2nd, 2005, 11:29 PM   #6
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
int s = SavitchIn.readInt();

What is SavitchIn ?
Also, ... use [code] when posting code.
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Apr 2nd, 2005, 11:42 PM   #7
solomon_13000
Newbie
 
Join Date: Apr 2005
Posts: 5
Rep Power: 0 solomon_13000 is on a distinguished road
SavitchIn is a function. I have the class to use it.
solomon_13000 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:04 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC