1. Create the following .java classes: Hospital, Person, Patient, Doctor 2. Hosp
ID: 644099 • Letter: 1
Question
1. Create the following .java classes: Hospital, Person, Patient, Doctor
2. Hospital.java will contain your main class. It should contain objects of the other three classes(Person, Patient and Doctor) which will contain the input. Create objects to display different output. Make sure input has the correct number of parameters. You will print the output of the other three classes from the Hospital class. You do not have to ask the user for input.
3. Class Person is the superclass. It will contain variables first name, last name, social security number(12-333-4567 is the format), and type(patient or doctor). Create methods to "get" the variables, like getFirstName, etc.
4. Class Patent is a subclass of Person. It will also contain variable patientNum(which must not be zero, use an expection(throw, etc.) to alert the user of an invalid number and hospitalFloor(4North is an example). Don't forget to return these variables back to hospital.
5. Class Doctor is also a subclass of Person. It will also contain variables speciality(Surgeon, etc.) and salary. Give a 5 percent raise to the doctor's salary within the Doctor class and pass it back to Hospital class.. Don't forget to return these variables back to hospital
Explanation / Answer
import java.util.*;
class Person{
protected String name;
protected String phone;
protected String address;
//Creates a new Person
public Person(String name, String phone, String address){
//fill in the missing code
}
//Returns the name of a Person
public String getName(){
//fill in the missing code
}
//Returns the phone number of this person
public String getPhone(){
//fill in the missing code
}
//Returns the address of this person
public String getAddress(){
//fill in the missing code
}
//Return person details
public String toString(){
//fill in the missing code
}
}
class Patient extends Person{
private int age;
private String recentTreatment;
private ArrayList<String> treamentHistory;
//Creates a new Customer
public Patient(String name, int age, String phone, String address){
//fill in the missing code
}
//Display this Patient's treament history
public void displayTreamentHistory(){
//fill in the missing code
}
//Return this Patient's current treament
public String getCurrentTreament(){
//fill in the missing code
}
//Returns the age of this patient
public int getAge(){
//fill in the missing code
}
//Receive treatement and add the treatment to the treatment history
public void receiveTreatment(String treatmentDescription){
//fill in the missing code
}
//Computes and displays this patient's bill
public void displayBill(){
//fill in the missing code
}
}
class Doctor extends Person{
protected String speciality;
protected ArrayList<Patient> patientsTreated;
//Creates a new Doctor
public Doctor(String name, String phone, String address, String speciality){
//fill in the missing code
}
//returns doctor's speciality
public String getSpeciality(){
//fill in the missing code
}
//Display patients treated todate
public void displayPatientsTreated(){
//fill in the missing code
}
}
//CanTreatPatient interface defines common methods for different specialisations
interface CanTreatPatient{
public void treatPatient(Patient p);
public void displayPatientsTreated();
}
class Surgeon extends Doctor implements CanTreatPatient{
//Creates a new Doctor
public Surgeon(String name, String phone, String address, String speciality){
//fill in the missing code
}
//Treat the patient and increment the patient's treatment counter
public void treatPatient(Patient p){
//fill in the missing code
}
}
class Dentist extends Doctor implements CanTreatPatient{
//Creates a new Doctor
public Dentist(String name, String phone, String address, String speciality){
//fill in the missing code
}
//Treat a patient
public void treatPatient(Patient p){
//fill in the missing code
}
}
//Driver class for testing your program
//You must not modify the code below
public class MUKHospitalSystem{
public static void main(String[] args){
System.out.println(" ");
Dentist dentist1 = new Dentist("Dr. Leo", "07681818", "MUK Hospital - Kla", "Dental");
Surgeon surgeon1 = new Surgeon("Dr. Lisa", "081981892", "Kla Hospital - Kla", "Dental");
Dentist dentist2 = new Dentist("Dr. Mercy", "067188923", "MUK Hospital - Kla", "Dental");
Patient patient1 = new Patient("Julian Billa", 24, "08790292", "Mak - Kla");
Patient patient2 = new Patient("James D.", 21, "06551617", "Mak - Kla");
Patient patient3 = new Patient("Mary K.", 19, "06677181", "Mak - Kla");
dentist1.treatPatient(patient1);
surgeon1.treatPatient(patient1);
surgeon1.treatPatient(patient2);
System.out.println(patient1);
patient1.displayTreamentHistory();
patient1.displayBill();
System.out.println(patient2);
patient2.displayTreamentHistory();
patient2.displayBill();
System.out.println(patient3);
patient3.displayTreamentHistory();
patient3.displayBill();
System.out.println(dentist1);
dentist1.displayPatientsTreated();
System.out.println(dentist2);
dentist2.displayPatientsTreated();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.