Question: Computer Science: Java programming QUESTION 1 Given the following hierarchy of superclass Patient and their subclasses: Inpatient and Out Patient and the definition for each
Computer Science: Java programming


QUESTION 1 Given the following hierarchy of superclass Patient and their subclasses: Inpatient and Out Patient and the definition for each superclass and subclasses Superclasss: Patient public abstract class Patient 1 protected String name: 7ame of patient protected long refid; //reference number protected boolean isForeigener; //true for foreigner //Methods: 1ormal constructor //accessors; getName(), getRefIDO), get Foreigner() //toString() - return information about the object public abstract double calPay(); //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 calPay() method definition Subclass: Outpatient public class Out Patient extends Patient ! private boolean i sEmergency; //true for emergency case private final double consultFee = 50.0; //Methods: /ormal constructor 1/accessors; getEmergency //toString() - return information about the object public double calPay() method definition a) Write the method definition of calPay() for both subclasses to calculate and returns the total payment that each patient has to pay based on the given information. For subclass inpatient, the payment will be based on the following table: Type of Room Bronze Silver Gold Platinum Price/Day (RM) 50.0 80.0 150.0 250.0 The foreigner needs to be paid an extra RM70 per day For subclass out Patient, the payment depends on: If the case is emergency, the charge is RM150, otherwise the charge is RM50. The consultation fee needs to be added to the total payment. For local patient, the discount of 20% will be given out of the total payment
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
