Question
EmployeeTester.java /** A class to demo the employee classes. */ public class EmployeeTester { public static void main(String[] args) { Employee e1 = new Employee(Jeff,
EmployeeTester.java
/** A class to demo the employee classes. */ public class EmployeeTester { public static void main(String[] args) { Employee e1 = new Employee("Jeff", 30000); Employee e2 = new Manager("Larry", 80000, "Sales"); Employee e3 = new Executive("Jayne", 800000, "Regional VP",20000); System.out.println(e1); System.out.println(e2); System.out.println(e3); System.out.println("Expected:Employee Name: Jeff Salary: 30000.0"); System.out.println("Manager Name: Larry Salary: 80000.0 Department: Sales"); System.out.println("Executive Name: Jayne Salary: 800000.0 Department: Regional VP Bonus: 20000"); } }
Employee.java
/** A class to model an employee. */ public class Employee { private String name; private double salary; /** Make an employee with a given name and salary. @param aName the name @param aSalary the salary */ public Employee(String aName, double aSalary) { name = aName; salary = aSalary; } /** Provide a string description of an employee. */ public String toString() { return this.getClass().getName() + " Name: " + name + " Salary: " + salary; } }
Manager.java
/** A class to model a manager. */ public class Manager extends Employee { private String department; /** Make a manager with a given name, salary, and department. @param name the name @param salary the salary @param department the department */ public Manager(String name, double salary, String dept) { //-----------Start below here. To do: approximate lines of code = 2 // Initialize the inherited variables name and salary using the super() keyword // initialize the new instance variable department //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } /** Provide a string description of a manager. */ public String toString() { //-----------Start below here. To do: approximate lines of code = 1 // Override the method toString() from super class Employee //Hint: use the super. (see toString() method in Employee) // and add " Department: " followed by the department name to the returned string //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } }
Executive.java
/** A class to model an executive. */ public class Executive extends Manager { private int bonus; /** Make an executive with a given name, salary, department and bonus. @param name the name @param salary the salary @param department the department @param bonus the bonus */ public Executive(String name, double salary, String department, int bonus) { //-----------Start below here. To do: approximate lines of code = 2 // Initialize the inherited variables using the super() keyword // also initialize the new instance variable bonus //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } /** Provide a string description of an executive. */ public String toString() { //-----------Start below here. To do: approximate lines of code = 1 // Override the method toString() from super class Manager //Hint: use the super. (see toString() method in Manager) // and add " Bonus: " followed by the bonus value to the returned string //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } }
P.s: please besides the code, also include a screenshot of the code, and the output to confirm the code doesn't get edited out and the output satisfies the problem!!
Purpose: practice extending classes and overriding a method in a subclass. This example has a sub sub class See the following files: * Employee Tester.java * Employee.java Manager.java (has todo) * Executive.java (has todo) * Approximate total lines of code required: 6Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started