Take the following code snippets (see below) and put them into a class called Employee. Then create two concrete (non-abstract) classes: Cashier and Supervisor Set the base salary of cashiers to be $30,000. Set the base salaries of supervisors to be $60,000. (use their constructors to do this). Create different methods for getMontlySalary() for the Cashier and Supervisor classes. a) for the Cashier class, just divide the basic salary by 12 to get the monthly. b) for the Supervisor class, also add a 10% bonus. So a supervisor before any raises would earn $5500 per month. (60,000/12 + 10%) Create an employee tester class. Add an array of 10 employees. put 8 cashiers and 2 supervisors into the array. Print out the complete records of all 10 employees using a for loop. (Hint: Overload the toString() on all Employee class). abstract class Employee { private String name, address; private int basicSalary; public String getName(){ return name; } public String getAddress(){ return address; } public int getBasicSalary(){ return basicSalary; } public void setAddress(String add){ address = add; } public void setName(String nm){ name = nm; } public void setBasicSalary(int sal){ basicSalary = sal; } public abstract int getMonthlySalary(); } // end class Employee
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Take the following code snippets (see below) and put them into a class called Employee.
- Then create two concrete (non-abstract) classes: Cashier and Supervisor
- Set the base salary of cashiers to be $30,000. Set the base salaries of supervisors to be $60,000. (use their constructors to do this).
- Create different methods for getMontlySalary() for the Cashier and Supervisor classes.
- a) for the Cashier class, just divide the basic salary by 12 to get the monthly.
- b) for the Supervisor class, also add a 10% bonus. So a supervisor before any
raises would earn $5500 per month. (60,000/12 + 10%)
- Create an employee tester class. Add an array of 10 employees. put 8 cashiers and 2 supervisors into the array. Print out the complete records of all 10 employees using a for loop. (Hint: Overload the toString() on all Employee class).
abstract class Employee {
private String name, address;
private int basicSalary;
public String getName(){ return name; }
public String getAddress(){ return address; }
public int getBasicSalary(){ return basicSalary; }
public void setAddress(String add){ address = add; }
public void setName(String nm){ name = nm; }
public void setBasicSalary(int sal){ basicSalary = sal; }
public abstract int getMonthlySalary();
} // end class Employee
Step by step
Solved in 2 steps with 1 images