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

Question #242664
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-27T02:59:18-0400


package employee;


import java.util.Scanner;
public class Employee {
private String name;
Employee(){
    
}
Employee(String n){
    name = n;
}
 public String toString(){
     return name;
 }  
 void setName(String n){
     name = n;
 }
   String getName(){
       return name+" "+getSalary()+" "+getHours()+" "+getLeaveDays() ;
   } 
   double getSalary(){
        
        double salary = 50000;
        return salary;
   }
   double getHours(){
       double hours= 37.5;
        return hours;
   }
   int getLeaveDays(){
      System.out.println("Enter leave days\n");
        Scanner scan = new Scanner(System.in);
        int days = scan.nextInt();
        return days; 
   }
   void leaveApplication(){
         System.out.println("18 workdays leaves \n");
       System.out.println("Enter the number of days\n");
       Scanner scan = new Scanner(System.in);
      int day= getLeaveDays();
       System.out.printf("You have successfully applied for: %d\n",day);
   }
   void work(){
       System.out.println("Employees should work 37.5 hours per week. \n");
   }
    public static void main(String[] args) {
       System.out.println("Select an option.\n1. Employee\n2. Manager\nSecretary \n");
       Scanner scan = new Scanner(System.in);
      int choice = scan.nextInt();
      if(choice==1){ 
          System.out.println("Enter employee name\n");
          String name = scan.next();
          Employee emp = new Employee(name);
         System.out.println("Details as follows:\n"+emp.toString());
      } 
      else if(choice==2){
          System.out.println("Enter Manager's Name\n");
          String name = scan.next();
          Manager emp = new Manager(name);
         System.out.println("Details as follows:\n"+emp.toString());
      }
      else if(choice == 3){
          System.out.println("Enter Secretary's Name\n");
          String name = scan.next();
          Secretary emp = new Secretary(name);
         System.out.println("Details as follows:\n"+emp.toString()); 
      }
      }
    
}
class Manager extends Employee{
    Manager(){
        
    }
    Manager(String name){
        super(name);
    }
    @Override
    int getLeaveDays(){
      System.out.println("Enter leave days\n");
        Scanner scan = new Scanner(System.in);
        int days = scan.nextInt();
        return days; 
   }
    @Override
    double getSalary(){
        
        double salary = 20000 + 50000;
        return salary;
   }
    
    @Override
     void leaveApplication(){
       System.out.println("18 workdays leaves \n");
       System.out.println("Enter the number of days\n");
       Scanner scan = new Scanner(System.in);
      int day= getLeaveDays();
       System.out.printf("You have successfully applied for: %d\n",day);
   }
    @Override
     void work(){
        System.out.println("Enter the number of hours you have worked\n");
       Scanner scan = new Scanner(System.in); 
       
       int workdays = scan.nextInt();
       System.out.printf("You have worked for %d\n",workdays);
       
     }
    
}


class Secretary extends Employee{
    Secretary(){
        
    }
    Secretary( String name){
        super(name);
    }
    @Override
     void work(){
       
       System.out.println("You have worked for "+ getHours());
       
     }
    @Override
     double getHours(){
        double hours = 40;
        return hours;
   }
}

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