In: Computer Science
Problem 6: (20 pts) Create two subclasses called outpatient and inpatient which inherit from the patient base class. The outpatient class has an additional data field called doctorOfficeID and the inpatient class has an additional data item called hospitalID. Write a main method that creates inpatient and outpatient objects. Sets data for these objects and display the data.
import java.io.*;
class patient{
String name,healthIssue,arrivalDate;
int age;
//constructor
patient(String name,int age,String healthIssue,String arrivalDate){
this.name = name;
this.age = age;
this.healthIssue = healthIssue;
this.arrivalDate = arrivalDate;
}
}
class outpatient extends patient{
int doctorOfficeID;
//constructor
outpatient(String name,int age,String healthIssue,String arrivalDate,int doctorOfficeID){
super(name,age,healthIssue,arrivalDate);
this.doctorOfficeID = doctorOfficeID;
}
void display() {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Health Issue: " + healthIssue);
System.out.println("Arrival Date: " + arrivalDate);
System.out.println("Doctor Office ID: " + doctorOfficeID + "\n");
}
}
class inpatient extends patient{
int hospitalID;
//constructor
inpatient(String name,int age,String healthIssue,String arrivalDate,int hospitalID){
super(name,age,healthIssue,arrivalDate);
this.hospitalID = hospitalID;
}
void display() {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Health Issue: " + healthIssue);
System.out.println("Arrival Date: " + arrivalDate);
System.out.println("Hospital ID: " + hospitalID + "\n");
}
}
class Main{
// **************MAIN METHOD**************
public static void main(String[] args)
{
outpatient p1 = new outpatient("Adam Stal",27,"Sickness","10/04/2018",353546);
inpatient p2 = new inpatient("Mary Joe",44,"Stomach Ache","12/08/2015",543466);
// Printing details of the patients
p1.display();
p2.display();
}
}
OUTPUT: