[Solved] Part 1 Concept Understanding Short Answer 15 Points Write First Line Calico Class Inherits Q37234417
Part 1,Concept Understanding — Short Answer (1.5points)
- Write the first line of a Calico class thatinherits from the Cat class.
- explain (in your own words) the differences between a protectedclass member and a private class member in terms of its visibilityand inheritance?
- When does dynamic binding happen?
This lab consists ofthe following files:
- Hospital.java (driver)
- HospitalEmployee.java (super class)
- Doctor.java (subclass of HospitalEmployee)
- Nurse.java (subclass of HospitalEmployee)
//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 Part 1, Concept Understanding — Short Answer (1.5 points) Write the first line of a Calico class that inherits from the… . . .
OR

