Question
Write the Java code for an abstract class named Employee which has two data members; one for the employee number and one for employee name
Write the Java code for an abstract class named Employee which has two data members; one for the employee number and one for employee name (use information hiding). The Employee class should include get and set methods for both data members and a constructor that initializes the two data members from the values received in the parameter list. Create (override) the toString() method that returns a string indicating the employee number and the employee name. In addition to these methods, the Employee class will have one abstract method called calculatePay. The calculatePay method will return a floating point amount representing the weekly pay. In addition to the Employee superclass, write the code for two subclasses: HourlyEmpl and SalaryEmpl. The HourlyEmpl weekly pay is calculated by multiplying its two data members together ( hourlyRate and no_of_hrs_worked). The SalaryEmpl pay is calculated by dividing its yearlySalary data member by 52 ( weeks in a year). The constructors of both subclasses should initialize all data members with the values passed in the constructors parameter list. Write the code for a class named TestEmployee that will create an array of 3 Employee references, instantiates two HourlyEmpl objects and one SalaryEmpl object, and then assigns the HourlyEmpl objects to the first two array elements in the array mentioned above, and the SalaryEmpl object to the third. Create a loop that calls the calculatePay method and then displays the employee number, employee name and weekly pay for all three employees using the array references.
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