Question: Modify the payroll system of Figs. 10.410.9 to include an additional Employee subclass PieceWorker that represents an employee whose pay is based on the number
Modify the payroll system of Figs. 10.4–10.9 to include an additional Employee subclass PieceWorker that represents an employee whose pay is based on the number of pieces of merchandise produced. Class PieceWorker should contain private instance variables wage (to store the employee’s wage per piece) and pieces (to store the number of pieces produced). Provide a concrete implementation of method earnings in class PieceWorker that calculates the employee’s earnings by multiplying the number of pieces produced by the wage per piece. Create an array of Employee variables to store references to objects of each concrete class in the new Employee hierarchy. For each Employee, display its String representation and earnings.
Fig. 10.4

Fig. 10.9
I // Fig. 10.4: Employee.java 2 // Employee abstract superclass. 3 4 5 6 7 8 9 10 || 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 W2NNN! 28 29 30 31 32 33 34 35 public abstract class Employee { private final String firstName; private final String lastName; private final String social SecurityNumber; } // constructor public Employee (String firstName, String lastName, String social SecurityNumber) { this.firstName = firstName; this.lastName = lastName; this.social SecurityNumber = social SecurityNumber; } // return first name public String getFirstName() {return firstName; } // return last name public String getLastName() {return lastName; } // return social security number public String get Social SecurityNumber() {return social SecurityNumber;} // return String representation of Employee object @Override public String toString() { return String.format("%s %s %nsocial security number: %s", getFirstName(), getLastName(), getSocial SecurityNumber()); } // abstract method must be overridden by concrete subclasses public abstract double earnings(); // no implementation here
Step by Step Solution
3.44 Rating (160 Votes )
There are 3 Steps involved in it
Based on the information provided and the requirement to create a subclass PieceWorker of the Employee class I will walk you through how to create thi... View full answer
Get step-by-step solutions from verified subject matter experts
