Menu

(Solved) : Lab Consists Following Files Hospitaljava Driver Hospitalemployeejava Super Class Doctorja Q37235102 . . .

This lab consists ofthe following files:

  1. Hospital.java (driver)
  2. HospitalEmployee.java (super class)
  3. Doctor.java (subclass of HospitalEmployee)
  4. Nurse.java (subclass of HospitalEmployee)

Report for a – d:

  • where in the code you get an error (list the methodname) and
  • what type of error; compiling orrun-time.
  • Explain what you think caused errors or changes inoutput (based on the concepts we studied in class).

a. do 1 and 2

1. (change HospitalEmployee.java )change the Employee issuePayCheck( ) method to beprivate in class HospitalEmployee

              2. (hospital.java) Add the following code as the last lines in themain():

HospitalEmployee[] he = newHospitalEmployee[2];

      he[0] =Lyons;

      he[1] =Nick;

      for(int i = 0; i < 2; i++) {

        he[i].issuePayCheck();

              }

Where was theerror?

What type oferror?

Youranalysis:

b .   (change HospitalEmployee.java ) changenetPay to be private in HospitalEmployee

Where was theerror?

What type oferror?

Youranalysis:

c. (change HospitalEmployee.java ) Add the keyword,final before the issuePayCheck()method

Where was theerror?

What type oferror?

Youranalysis:

  1. (Doctor.java ) In the conversion constructor for Doctor,comment out the call to the conversion constructor of classHospitalEmployee

// super( …)

Note how this output differsfrom the previous/normal running of the program. Whathappened? If you aren’t sure, add a breakpoint to the lineand trace the code execution (then refer to Exercise 1 where youtraced the constructors

Answer:

//Doctor

public class Doctorextends HospitalEmployee
{
protected String specialty;
protected String insurer;
protected double salary;

public Doctor (String name, String SSN, int dep, String special,String ins)
{
super (name, SSN, dep);
specialty = special;
insurer = ins;
salary = 2345.67;
}
/**
* specific to each HospitalEmployee
* @return
*/
protected void issuePayCheck() {
netPay = salary;
System.out.println(“————————————————-“);
System.out.println ( “Staff Physician”);
System.out.println(” Name: ” + getName() + “tID ” + ssn);
System.out.println(“nnAmount electronically deposited: $” +netPay);
System.out.println(“————————————————-“);
}
//—————————————————————–
// Sets this doctor’s specialty.
//—————————————————————–
public void setSpecialty (String special)
{
specialty = special;
}

//—————————————————————–
// Returns this doctor’s specialty.
//—————————————————————–
public String getSpecialty()
{
return specialty;
}

//—————————————————————–
// Sets this doctor’s insurer.
//—————————————————————–
public void setInsurer (String ins)
{
insurer = ins;
}

//—————————————————————–
// Returns this doctor’s insurer.
//—————————————————————–
public String getInsurer()
{
return insurer;
}

//—————————————————————–
// Returns a description of this doctor as a string.
//—————————————————————–
public String toString()
{
String output = “Staff Physician “;
output += super.toString();
output += “Specialty: ” + specialty + “tInsurance: ” + insurer +”n”;
return output;
}

}

//Hospital

public classHospital
{
//—————————————————————–
// Creates several objects from classes derived from
// HospitalEmployee.
//—————————————————————–
public static void main (String[] args)
{
  
Doctor Lyons = new Doctor(“Dan D. Lyons”, “234-76-4321”, 5,
“Podiatry”, “CIGNA”);
  
Nurse Nick = new Nurse(“Nick O’Teen”, “789-11-2314”, 3, 35, 30,2);
  

// print theemployees
System.out.println(Lyons);
System.out.println(Nick);

// invoke the specific methods of the objects
Lyons.issuePayCheck();
Nick.issuePayCheck();

}
}

//HospitalEmployee

importjava.util.Scanner;

public classHospitalEmployee
{
protected String name; // Employee’s name provided
protected String ssn; // Employee’s ssn provided
protected double netPay; // Employee’s netPay…must becalculated
private int dependents; // Employee’s number of dependentsprovided

//—————————————————————–
// Creates a hospital employee by asking user for specifiedinformation.
//—————————————————————–
public HospitalEmployee()
{
Scanner input = new Scanner(System.in);
System.out.print(” Please enter the employee’s name > “);
name = input.nextLine();
System.out.print(” Please enter the employee’s SSN > “);
ssn = input.nextLine();
System.out.print(” Please enter the employee’s number ofdependents> “);
dependents = input.nextInt();
netPay = 0;
  
}

//—————————————————————–
// Sets up this hospital employee with the specifiedinformation.
//—————————————————————–
public HospitalEmployee (String empName, String ssNumber, intnumDepend)
{
name = empName;
ssn = ssNumber;
netPay =0;
dependents = numDepend;
}

//—————————————————————–
// Sets the name for this employee.
//—————————————————————–
public void setName(String empName) {
name = empName;
}
//—————————————————————–
// Sets the employee ss number for this employee.
//—————————————————————–
public void setSSN (String empNumber)
{
ssn = empNumber;
}
//—————————————————————–
// Sets the number of dependents for this employee.
//—————————————————————–
public void setDependents(int depNumber) {
dependents = depNumber;
}

//—————————————————————–
// Returns this employee’s name.
//—————————————————————–
public String getName()
{
return name;
}

//—————————————————————–
// Returns this employee’s ss number.
//—————————————————————–
public String getSSN()
{
return ssn;
}

//—————————————————————–
// Returns this employee’s netPay amount.
//—————————————————————–
public double getPay()
{
return netPay;
}

//—————————————————————–
// Returns this employee’s number of dependents.
//—————————————————————–
public int getDependents()
{
return dependents;
}
/**
* method to issue ALL employees a W2
*/
public void issueW2()
{

}
/**
* specific to each HospitalEmployee
* @return
*/
private void issuePayCheck() {
System.out.println(” You should not see this message!”);
}
//—————————————————————–
// Returns a description of this employee as a string.
//—————————————————————–
public String toString()
{
return name + “t” + ssn + “tNumber of Dependents: ” + dependents+”n”;
}
}

//Nurse

public class Nurseextends HospitalEmployee
{
protected double hoursWorked;
protected double shiftDifferential;
protected double hourlyRate;

/**
* Conversion Constructor for a Nurse object
* @param empName
* @param empSSN
* @param dep
* @param hours
* @param rate
* @param shift
*/
public Nurse(String empName, String empSSN, int dep, doublehours,
double rate, double shift) {
super (empName, empSSN, dep);
hoursWorked = hours;
shiftDifferential = shift;
hourlyRate = rate;
}

/**
* Mutator: setHourlyRate
* Sets the hourly rate of pay for this nurse.
*/
public void setHourlyRate (int hrate)
{
hourlyRate = hrate;
}

/**
* Accessor: getHourlyRate()
* @return this nurse’s current hourly rate of pay.
*/
public double getHourlyRate()
{
return hourlyRate;
}
//—————————————————————–
// Sets the hours worked for this nurse.
//—————————————————————–
public void setHoursWorked (int hrs)
{
hoursWorked = hrs;
}

//—————————————————————–
// Returns this nurse’s hours.
//—————————————————————–
public double getHoursWorked()
{
return hoursWorked;
}
/**
//—————————————————————–
// Issue nurse’s paystub.
//—————————————————————–
*/
protected void issuePayCheck()
{
netPay = hoursWorked * hourlyRate;
System.out.println(“————————————————-“);
System.out.println ( “Nursing Staff”);
System.out.println(” Name: ” + getName() + “tID ” + ssn);
System.out.println(“nnAmount electronically deposited: $” +netPay);
System.out.println(“————————————————-“);
}
//—————————————————————–
// Returns a description of this nurse as a string.
//—————————————————————–
public String toString()
{
String output = ” Nurse “;
output += super.toString() + ” has worked: ” + hoursWorked
+ ” this weekn”;
return output;
}

}

Expert Answer


Answer to This lab consists of the following files: Hospital.java (driver) HospitalEmployee.java (super class) Doctor.java (subcla…

OR