Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Form the subclass Manager from the class Employee. A Manager has a bonus. Supply a constructor to the Manager class that takes id, salary and
Form the subclass Manager from the class Employee. A Manager has a bonus.
Supply a constructor to the Manager class that takes id, salary and bonus of a Manager. The constructor initializes all the instance variables of a Manager object.
The toString method of Manager should yield a string such as
id = 222 salary = 15.0 bonus = 5.0
public class Manager { private double bonus; } public class Employee { private int id; private double salary; public Employee (int theID, double theSalary) { id = theID; salary = theSalary; } public String toString() { return "id = " + id + " salary = " + salary; } }
Here is a tester.
public class EmployeeTester { public static void main(String [] args) { Employee e1 = new Employee(111, 10.0); Employee e2 = new Manager (222, 15.0, 5.0); System.out.println(e1.toString()); //prints id = 111 salary = 10.0 System.out.println(e2.toString()); //prints id = 222 salary = 15.0 bonus = 5.0 } }
Step 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