Answer to Question #242663 in Java | JSP | JSF for Aubrey Eso Jozela

Question #242663
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. Calculate, and then display, the average salary of all employees. Calculate and display the cost of the leave to the company for each employee. f type code these object values.
1
Expert's answer
2021-09-27T04:52:54-0400
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());
       ​}
   ​}
} 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS