Question: Help please, code in java /** Illustration of inheritance and polymorphism Employee: each employee has a name, address, get pay, and get a check +
Help please, code in java
/** Illustration of inheritance and polymorphism
Employee: each employee has a name, address, get pay, and get a check + hourly employee: has hours worked and hourly pay rate + salary employee: has an annual salary and get pay monthly + contracted employee: get pay a lump sum by the contract amount TO DO: 1.In the Employee class, + complete the printCheck method taht display the employee's information, the total amount pay, the deductions, and the actual amount paid. + Add a raise method by a given percentage. 2.In the HourlyEmployee, + add a method to add the worked hour for hourly employee 3. Complete the salary employee as specified 4. Complete the contracted employee, make sure to override the raise method because the contacted employee don't get raises OPTIONAL 5. override the printCheck method to add the hour worked and pay rate for hourly employee on the check */
abstract class Employee{ private String name; protected String address; //constructor public Employee(String name, String address){ this.name = name; this.address = address; } public abstract double getPay(); //printCheck - from getPay => tax 10%, ss tax 5%, insurance 2% }
class HourlyEmployee extends Employee{ private double payRate; private double hoursWorked; //constructor public HourlyEmployee(String name, String address, double payRate){ super(name, address); //call base class constructor this.payRate = payRate; this.hoursWorked = 0; } /** ...*/ public double getPay(){ double pay = this.payRate * hoursWorked; this.hoursWorked = 0; //reset work hours return pay; } }
/** Driver/ Application TO DO: 1. create a list of different types of employees.Does not have to come from users 2. print checks for every employee 3. give a raise to all employees
OPTIONAL 4. print checks for all employees that are hourly */
public class HR2{ public static void main(String[] args){ //testing Hourly employee HourlyEmployee e1 = new HourlyEmployee("Ken", "123 Tara Blvd.", 5.25); System.out.println("Paid: " + e1.getPay()); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
