rogram 6 – Employee rules Code the following program in Java. There will be many source files. Most employees work 37.5 hours per week. Most employees earn R50 000 per year. Managers earn R20 000 extra per year. Most employees get 15 workdays leaves a year. Managers get an extra 3 days leave per year. Secretaries must work 40 per week. Everybody must apply for leave online. Managers also need to get the approval of the CEO of the company when taking leave. Employees knows how to work. Managers knows how to manage and secretaries knows how to type. Code your classes according to the following class diagram. Name is the only attribute you need.Required 1. : Code the classes Employee, Manager and Secretary. 2. Extra Code an application with a main method. In this class you must code an array o Employee with a maximum size of 20. a. b. c. Add a minimum of 10 objects to the array. You may hard The objects must be a mixture of Employee, Manager and Secretary. Display all the objects on the screen.
public class Employee {
private String name;
public Employee(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
public class Manager extends Employee{
public Manager(String name){
super(name);
}
}
public class Secretary extends Employee {
public Secretary(String name) {
super(name);
}
}
import java.util.Random;
public class Main {
public static void main(String[] args) {
Employee[] employees = new Employee[20];
String[] names = {"Tom", "Lisa", "Bob", "Roger", "Tim", "Leo", "Nick", "David", "Sarah", "Lucie"};
for (int i = 0; i < names.length; i++) {
employees[i] = new Random().nextBoolean() ?
(new Random().nextBoolean() ? new Manager(names[i]) : new Employee(names[i]))
: new Secretary(names[i]);
}
for (int i = 0; i < names.length; i++) {
System.out.println(employees[i].getName());
}
}
}
Comments
Leave a comment