Question: Question b) the answer in JAVA (Object-oriented programming). How to do this? Given the following hierarchy of superclass Patient and their subclasses; Inpatient and Outpatient


Question b) the answer in JAVA (Object-oriented programming). How to do this?
Given the following hierarchy of superclass Patient and their subclasses; Inpatient and Outpatient and the definition for each superclass and subclasses Superclasss: Loan public abstract class Patient { protected String name; protected long refid; protected boolean isMalaysia; /ame of patient //reference number //true for Malaysia //Methods: /ormal constructor //accessors; getName(), getRefIDO, getMalaysia () //tostring() - return information about the object public abstract double calcost(); //abstract method } Subclass: Inpatient public class Inpatient extends Patient { { private String roomType; //room type private int numDay; /umber of days warded //Methods: /ormal constructor //accessors; getRoom(), getNumDay ( //toString() - return information about the object public double calcost() { method definition } } Subclass: Outpatient public class Out Patient extends Patient { { private String medicineType; 1ormal or special private final double consult Fee = 30.0; = //Methods: /ormal constructor //accessors; getMediType() //toString() - return information about the object public double calcost() { method definition } } b) Assume that the following array of object had been declared: Patient[ pn = new Patient [50]; Write a Java application class that uses the concept of polymorphism to perform the following tasks: i) Calculate and display the total cost made by every patient for each subclass, Inpatient and Out Patient (5 marks) ii) Count the number of patients that warded in the platinum room type, display the respective information about every patient in the platinum room and the total platinum room based on counter. (6 marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
