It is a common practice that in a business place employees get salary raise based on different criteria such as the position of the employee, job performance, department budget, sales proportion (if the employee is directly involved in sales), etc. In this question, you are going to implement the salary raise scheme for a standard work place.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Write an Employee class that describes an employee with employeeID, firstName, lastName, and salary fields.
Also write a constructor in Employee class that initializes all data fields. Create three different subclasses from class Employee as follows:
1)A Manager subclass that invokes super class’ constructor to initialize its fields and implements the raise method with a 10% increment to the original salary.
2) A SalesAssociate subclass that invokes super class’ constructor to initialize its fields. It should have an extra data field for commission and the raise for a sales associate should be calculated by adding the base salary and the commission amount.
3) A Secretary subclass that invokes super class’ constructor to initialize its fields and implements the raise method with a 5% increment to the original salary
Write a driver class TestEmployee to create an array of three elements: one manager, one sales associate, and one secretary and initialize each with arbitrary initial values that you choose. Calculate the salary raise for each employee and display them in well formatted way to standard output (screen).
Hint: Since we won’t know in advance how method raise() is to be implemented, you need to define raise() method as abstract in the Employee class.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please, help! Here's my code. Please , check if it satisfies the conditions above. I usually make a lot of mistakes. Thank you!!! Sorry for the format, I am new to this forum
abstract class Employee { protected int employeeID; protected String firstName; protected String lastName; protected double salary; public Employee(int employeeID, String firstName, String lastName, double salary) { this.employeeID = employeeID; this.firstName = firstName; this.lastName = lastName; this.salary = salary; } public abstract void raise(); } class Manager extends Employee { public Manager(int employeeID, String firstName, String lastName, double salary) { super(employeeID, firstName, lastName, salary); } @Override public void raise() { salary = 1.1 * salary; } @Override public String toString() { return "Manager [employeeID=" + employeeID + ", firstName=" + firstName + ", lastName=" + lastName + ", salary=" + salary + "]"; } } class SalesAssociate extends Employee { private double commission; public SalesAssociate(int employeeID, String firstName, String lastName, double salary, double commission) { super(employeeID, firstName, lastName, salary); this.commission = commission; } @Override public void raise() { salary += commission; } @Override public String toString() { return "SalesAssociate [commission=" + commission + ", employeeID=" + employeeID + ", firstName=" + firstName + ", lastName=" + lastName + ", salary=" + salary + "]"; } } class Secretary extends Employee { public Secretary(int employeeID, String firstName, String lastName, double salary) { super(employeeID, firstName, lastName, salary); } @Override public void raise() { salary = 1.05 * salary; } @Override public String toString() { return "Secretary [employeeID=" + employeeID + ", firstName=" + firstName + ", lastName=" + lastName + ", salary=" + salary + "]"; } } public class TestEmployee { public static void main(String[] args) { Employee e1 = new Manager(1, "Larry", "Paul", 99.99); Employee e2 = new SalesAssociate(2, "Mary", "Janice", 97.2, 0.55); Employee e3 = new Secretary(3, "Jay", "Peace", 88); Employee[] es = new Employee[] { e1, e2, e3 }; for (Employee e : es) { System.out.println("Before raise"); System.out.println(e); System.out.println("After raise"); e.raise(); System.out.println(e); System.out.println(); } } }