Required:
1. Code the classes Employee, Manager and Secretary.
2. Code an application with a main method. In this class you must code an array of type Employee with a maximum size of 20.
a. Add a minimum of 10 objects to the array. You may hard-code these object values. The objects must be a mixture of Employee, Manager and Secretary.
b. Display all the objects on the screen.
c. Calculate, and then display, the average salary of all employees.
Extra
Calculate and display the cost of the leave to the company for each employee.
import java.util.Scanner;
class Employee {
public Employee() {
System.out.println("Employee!");
}
public Employee(String name) {
System.out.println(name);
}
}
class Manager{
public Manager() {
System.out.println("Manager!");
}
public Manager(String name) {
System.out.println(name);
}
}
class Secretary{
public Secretary() {
System.out.println("Secretary!");
}
public Secretary(String name) {
System.out.println(name);
}
}
public class Main {
public static void main(String[] args) {
int sum=0;
Scanner input=new Scanner(System.in);
System.out.print("Enter the average salary of the employees: ");
for(int i=0;i<20;i++){
sum += input.nextInt();}
double average=sum/20;
System.out.println("Average salary of the employees is: ");
System.out.println(average);
int leave=3000;
System.out.println("Cost of leave for each employee is: ");
System.out.println(leave);
}
}
Comments
Leave a comment