Question: (Java) We like to computerize the billing system of a hospital. * Desi
ID: 3708037 • Letter: Q
Question
Question: (Java) We like to computerize the billing system of a hospital.
* Design a class named personType, with 3 private member fields to store the first name, last name, and gender of a person. Define a constructor to set values to the member fields. Define accessor and mutator methods for the private member fields. Define a toString() method to return the values of the member fields.
* Design a class named dateType, with 3 private member fields to store the month number, day number, and year number (all integers). Define a constructor and define the mutator and accessor methods. Define a toString() method to return the values of the member fields.
* Design a class named billType with data members to store a patient’s ID and a patient’s hospital charges such as pharmacy charges for medicine, doctor’s fee, and room charges. Add appropriate constructors and member methods to initialize, access, and manipulate data members.
* Design a class named doctorType inherited from the class personType with an additional member to store a doctor’s specialty. Add appropriate constructors and member methods to initialize, access, and manipulate data members.
* Design a class named patientType inherited from the class personType with additional data members to store a patient’s ID, age, date of birth, attending physician’s name, the date when the patient was admitted to the hospital, and the date when the patient was dismissed from the hospital. IMPORTANT NOTE: use the class dateType to store the date of birth, admit date, discharge date (Month, Day, Year). Use the class doctorType to store the attending physician’s name. Add appropriate constructors and member methods to initialize, access, and manipulate data members.
Your main program file must have code to properly test all your classes by creating various objects using the different constructors. I also need you to show the definition and use of an array of patients using the patientType class. Your testing must be complete. For example, one should be able to enter data for a set of patients and be able to see the results outputted to the screen. Avoid minimal testing of your code. The program must also have some way of processing input as you test your code.
Explanation / Answer
import java.util.*;
class PersonType // base class
{
private String firstName, lastName,gender;
PersonType(String firstName, String lastName,String gender)//argument constructor
{
this.firstName = firstName;
this.lastName = lastName;
this.gender = gender;
}
//set and get methods
public void SetFirstName(String firstName)
{
this.firstName = firstName;
}
public String getFirstName()
{
return firstName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public String getLastName()
{
return lastName;
}
public void setGender(String gender)
{
this.gender = gender;
}
public String getGender()
{
return gender;
}
public String toString()
{
return " Firstname : "+firstName+" LastName : "+lastName +" Gender : "+gender;
}
};
class DateType
{
private int day, year, month;
public DateType(int day,int month, int year)
{
this.day = day;
this.month = month;
this.year = year;
}
public void setDay()
{
this.day = day;
}
public int getDay()
{
return day;
}
public void setMonth(int month)
{
this.month = month;
}
public int getMonth()
{
return month;
}
public void setYear(int year)
{
this.year = year;
}
public int getYear()
{
return year;
}
public String toString()
{
return " "+day+"/"+month+"/"+year;
}
};
class DoctorType extends PersonType
{
private String speciality;
public DoctorType(String firstName,String lastName,String gender,String speciality)
{
super(firstName,lastName,gender); // sending arguments to base class constructor
this.speciality = speciality;
}
public void SetSpeciality(String Speciality)
{
this.speciality = speciality;
}
public String getSpeciality()
{
return speciality;
}
public String toString()
{
return super.toString()+ " Speciality : "+speciality;
}
}
class PatientType extends PersonType
{
private int patientID, patientAge;
private DateType dob,dateAdmitted,dateDismissed;
private DoctorType physicianName;
PatientType(String firstName,String lastName,String gender,int patientID,int patientAge,DateType dob,DateType dateAdmitted,DateType dateDismissed,DoctorType physicianName)
{
super(firstName,lastName,gender);
this.patientID = patientID;
this.patientAge = patientAge;
this.dob = dob;
this.dateAdmitted = dateAdmitted;
this.dateDismissed = dateDismissed;
this.physicianName = physicianName;
}
public String toString()
{
return super.toString()+" Patient ID : "+patientID+" Age : "+patientAge+" Date of Birth : "+dob+
" Dae Admitted: "+dateAdmitted +" Date dismissed : "+dateDismissed+" Physician "+physicianName;
}
}
class BillType
{
private int patientId;
private double medicineCharge;
private double doctorFee;
private double roomCharges;
public BillType(int id,double mCharge,double dFee,double rCharges)
{
patientId = id;
medicineCharge = mCharge;
doctorFee = dFee;
roomCharges = rCharges;
}
public String toString()
{
return " Patient Id : "+patientId+ " Total Bill : $"+(medicineCharge+doctorFee+roomCharges);
}
}
class Test
{
public static void main (String[] args)
{
Scanner input = new Scanner(System.in);
String name,firstName,firstName1,lastName,lastName1,gender,gender1,speciality;
int patientId,age,day,day1,day2,month,month1,month2,year,year1,year2;
DoctorType dt = new DoctorType("Harris","Jones","Male","Heart");
System.out.println(dt);
PatientType[] pt = new PatientType[2];
for(int i=0;i<2;i++)
{
System.out.println("Enter patient first Name : ");
firstName = input.next();
System.out.println("Enter patient last Name : ");
lastName = input.next();
System.out.println("Enter the gender of Patient : ");
gender = input.next();
System.out.println("Enter patient id : ");
patientId = input.nextInt();
System.out.println("Enter the age of patient : ");
age = input.nextInt();
System.out.println("Enter the date of birth of patient : ");
day = input.nextInt();
month = input.nextInt();
year = input.nextInt();
DateType dob = new DateType(day,month,year);
System.out.println("Enter the date of admission : ");
day1 = input.nextInt();
month1 = input.nextInt();
year1 = input.nextInt();
DateType dateAdmitted = new DateType(day1,month1,year1);
System.out.println("Enter the date of dismissed : ");
day2 = input.nextInt();
month2 = input.nextInt();
year2 = input.nextInt();
DateType dateDismissed = new DateType(day2,month2,year2);
System.out.println("Enter the physician firstName,lastName,gender and speciality : ");
firstName1 = input.next();
lastName1 = input.next();
gender1 = input.next();
speciality = input.next();
DoctorType dt1 = new DoctorType(firstName1,lastName1,gender1,speciality);
pt[i] = new PatientType(firstName,lastName,gender,patientId,age,dob,dateAdmitted,dateDismissed,dt1);
System.out.println(pt[i]);
}
BillType bt = new BillType(1005,56.7,451.50,34.8);
System.out.println(bt);
}
}
Output:
Firstname : Harris LastName : Jones Gender : Male Speciality : Heart
Enter patient first Name :
Enter patient last Name :
Enter the gender of Patient :
Enter patient id :
Enter the age of patient :
Enter the date of birth of patient :
Enter the date of admission :
Enter the date of dismissed :
Enter the physician firstName,lastName,gender and speciality :
Firstname : John LastName : Smith Gender : Male Patient ID : 2056 Age : 43 Date of Birth :
3/3/1975 Dae Admitted:
5/3/2016 Date dismissed :
7/4/2016 Physician
Firstname : Harris LastName : Jones Gender : Male Speciality : Heart
Enter patient first Name :
Enter patient last Name :
Enter the gender of Patient :
Enter patient id :
Enter the age of patient :
Enter the date of birth of patient :
Enter the date of admission :
Enter the date of dismissed :
Enter the physician firstName,lastName,gender and speciality :
Firstname : Cathy LastName : Williams Gender : Female Patient ID : 2078 Age : 65 Date of Birth :
7/12/1951 Dae Admitted:
5/6/2017 Date dismissed :
10/7/2017 Physician
Firstname : Harris LastName : Jones Gender : Male Speciality : Heart
Patient Id : 1005
Total Bill : $543.0
Do ask if any doubt. Please upvote.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.