Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

zyDE 10.8.1: Inheritance: Employees and overriding a class method. The classes below describe a superclass named EmployeePerson and two derived classes, Employee Manager and EmployeeStaff,

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribedimage text in transcribed

zyDE 10.8.1: Inheritance: Employees and overriding a class method. The classes below describe a superclass named EmployeePerson and two derived classes, Employee Manager and EmployeeStaff, each of which extends the Employee Person class. The main program creates objects of type EmployeeManager and EmployeeStaff and prints those objects. 1. Run the program, which prints manager data only using the Employee Person class' printinfo method. 2. Modify the EmployeeStaff class to override the Employee Person class' printinfo method and print all the fields from the EmployeeStaff class. Run the program again and verify the output includes the manager and staff information. 3. Modify the Employee Manager class to override the Employee Person class' printinfo method and print all the fields from the Employee Manager class. Run the program again and verify the manager and staff information is the same. Current file: EmployeeMain.java - Load default template... public class EmployeeMain { public static void main(String[] args) { // Create the objects EmployeeManager manager = new EmployeeManager (25); EmployeeStaff staffi = new EmployeeStaff("Michele"); // Load data into the objects using the Person class' method manager.setData("Michele", "Sales", "03-03-1975", 70000); staff1.setData ("Bob", "Sales", "02-02-1980", 50000); // Print the objects manager.printInfo(); staff1.printInfo(); Current file: EmployeePerson.java - Load default template... // Format: last name, first name public class EmployeePerson { protected String fullName; protected String departmentCode; protected String birthday; protected int annualSalary; // Default constructor. Set protected variables to the empty string or 0 public EmployeePerson() { fullName = "" departmentCode birthday annualSalary = 0; / ************************ // Constructor with parameters to set the private variables Current file: EmployeePerson.java - Load default template... // ************************* * * * * * * * * * // Constructor with parameters to set the private variables public EmployeePerson(String empFullName, String empDepartmentCode, String empBirthday, int empAnnualSalary) { setData(empFullName, empDepartmentCode, empBirthday, empAnnualSalary); // ********* ** ** ******* ***** **** **** ** ** * ******* **** ** * * public void setData(String empFullName, String empDepartmentCode, String empBirthday, int empAnnualSalary) { fullName = empFullName; departmentCode = empDepartmentCode; birthday = empBirthday; annualSalary = empAnnualSalary; ****** Run Current file: EmployeePerson.java Load default template... // ************************* ******************************** public void setData(String empFullName, String empDepartmentCode, String empBirthday, int empAnnualSalary) { fullName = empFullName; departmentCode = empDepartmentCode; birthday = empBirthday; annualSalary = empAnnualSalary; * // ******** *** ** ** public void printInfo() { System.out.print("Name:" + fullName + ", Department: " + department Code + ", Birthday: " + birthday + ", Salary: " + annualSalary); Run Current file: EmployeeManager.java- Load default template... public class EmployeeManager extends EmployeePerson { private int numManaged; // Number of staff managed // ******** ******************* // Default constructor public EmployeeManager() { numManaged = 0; // ********** // Constructor with parameters public EmployeeManager(int nManaged) { numManaged = nManaged; // ************************************** * * ********** **** ** **** * Run Current file: EmployeeManager.java- Load default template... // Constructor with parameters public EmployeeManager(int nManaged) { numManaged = nManaged; // **** // Get the number of people managed public int getNumManaged() { return numManaged; // ********************* ************************ // FIXME: Override the EmployeePerson class' printInfo method with a // FIXME: printInfo method to print all manager fields here. Run Current file: EmployeeStaff.java Load default template... public class EmployeeStaff extends EmployeePerson { private String managerName; // *********** // Default constructor public EmployeeStaff() { managerName = ""; // ********************* // Constructor with parameters public EmployeeStaff (String reportsto) { managerName = reportsTo; 20 // *** **** *** ** *** **** ***** **** ** ***** ************ **** **** **** * ** * ******* * * Run Current file: EmployeeStaff.java Load default template... managerName = reports To; // ***** // Get the name of the manager public String getManagerName() { return managerName; // ************************** * **** **** ** ** *** * *** // FIXME: Override the EmployeePerson class' printInfo method with a // FIXME: printInfo method to print all staff fields. @Override public void printInfo() { 35 } 36 Run

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

1st Edition

1597496251, 978-1597496254

More Books

Students also viewed these Databases questions