Class HospitalEmployee should be an abstract class Remove the definition for the
ID: 3556607 • Letter: C
Question
Class HospitalEmployee should be an abstract class
Remove the definition for the issuePayCheck() method
Verify that you cannot create HospitalEmployee objects in Hospital.main() by attempting to declare:
HospitalEmployee newHire = new HospitalEmployee();
(leave this in your code, but commented out)
Create a static class member for HospitalEmployee named benefitsDeduction, type double that = 122.50. All hospital employees will have this amount subtracted from their base pay.
Format the netPay in the issuePayCheck() methods to have two digits after the decimal point.
Create two new subclasses for the HospitalEmployee hierarchy
OR (operating room) (integer number 1
Explanation / Answer
Program Code:
public class Hospital
{
public static void main(String args[])
{
HospitalEmployee[] vito = new HospitalEmployee[8];
vito[0]= new Administrator("Vito", 123);
vito[1]=new Administrator("Luca", 375);
vito[2]=new Surgeon("Seema",1232, "Gynic", false);
vito[3]=new Surgeon("Amy",453,"heart",true);
vito[4]=new Nurse();
vito[5]=new Nurse();
vito[6]=new Doctor();
vito[7]=new Doctor();
}
}
class HospitalEmployee
{
protected String name;
protected int number;
public HospitalEmployee(String empName, int empNumber)
{
name = empName;
number = empNumber;
}
public HospitalEmployee()
{
this.name="";
this.number=0;
}
public void setName(String empName)
{
name = empName;
}
public void setNumber(int empNumber)
{
number = empNumber;
}
public String getName()
{
return name;
}
public int getNumber()
{
return number;
}
public String toString()
{
return name + " " + number;
}
public void work()
{
System.out.println (name + " works for the hospital.");
}
public void calculatePay()
{
}
}
class Administrator extends HospitalEmployee
{
protected String department;
protected int salary, bonus;
public Administrator()
{
super ();
this.department="";
this.salary=0;
this.bonus=0;
}
public Administrator(String empName, int empNumber)
{
super (empName, empNumber);
}
public void setDepartment (String dept)
{
department = dept;
}
public String getDepartment()
{
return department;
}
public void setSalary (int sal)
{
salary=sal;
}
public int getSalary()
{
return salary;
}
public void setBonus (int bon)
{
bonus=bon;
}
public int getBonus()
{
return bonus;
}
public String toString()
{
return super.toString() + " works in " + department;
}
public void administrate()
{
System.out.println (name + "works in the" +department + " department.");
}
}
class Surgeon extends HospitalEmployee
{
protected boolean operating;
public Surgeon (String empName, int empNumber,String special, boolean isOper)
{
super (empName, empNumber, special);
operating = isOper;
}
public void setIsOperating (boolean isOper)
{
operating = isOper;
}
public boolean getIsOperating()
{
return operating;
}
public String toString()
{
return super.toString() + " Operating: " + operating;
}
public void operate()
{
System.out.print (name + " is");
if (!operating)
System.out.print (" not");
System.out.println ("operating now.");
}
}