Answer to Question #232169 in Java | JSP | JSF for Chadwin Fritz

Question #232169

Employee

-name: String

+Employee() <<constructor>>

+Employee(String)<<constructor>>

+toString(): String

+setName(String): void

+getName(): String

+getSalary(): double

+getHours(): double

+getLeaveDays(): int

+leaveApplication(): void

+work(): void

 

Manager

+Manager()<<constructor>>

+Manager(String)<<constructor>>

+getLeaveDays(): int

+getSalary(): double

+leaveApplication(): void

+work(): void

 

Secretary

+Secretary()<<constructor>>

+Secretary(String)<<constructor>>

+getHours(): double

+work(): void

 

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.


1
Expert's answer
2021-09-02T00:53:37-0400


class Employee {
	private String name;
	private double salary;
	private int hours;
	private int leaveDays;


	public Employee() {


	}


	public Employee(String name) {
		this.name = name;
	}


	public Employee(String name, double salary, int hours, int leaveDays) {
		this.name = name;
		this.salary = salary;
		this.hours = hours;
		this.leaveDays = leaveDays;
	}


	public void setName(String name) {
		this.name = name;
	}


	public String getName() {
		return name;
	}


	public double getSalary() {
		return salary;
	}


	public double getHours() {
		return hours;
	}


	public int getLeaveDays() {
		return leaveDays;
	}


	public void leaveApplication() {
		System.out.println(" leave application");
	}


	public void work() {
		System.out.println(" work");
	}


	@Override
	public String toString() {
		return "Name: " + this.name + "\n" + "Salary: " + this.salary + "\n" + "Hours: " + this.hours + "\n"
				+ "Leave days: " + this.leaveDays + "\n";
	}


}


class Manager extends Employee {
	public Manager() {


	}


	public Manager(String name) {
		super(name);
	}


	public Manager(String name, double salary, int hours, int leaveDays) {
		super(name, salary, hours, leaveDays);
	}


	public void leaveApplication() {
		System.out.print("Manager");
		super.leaveApplication();
	}


	public void work() {
		System.out.print("Manager");
		super.work();
	}
}


class Secretary extends Employee {
	public Secretary() {


	}


	public Secretary(String name) {
		super(name);
	}


	public Secretary(String name, double salary, int hours, int leaveDays) {
		super(name, salary, hours, leaveDays);
	}


	public void leaveApplication() {
		System.out.print("Secretary");
		super.leaveApplication();
	}


	public void work() {
		System.out.print("Secretary");
		super.work();
	}
}


public class EmployeesApp {


	public static void main(String[] args) {
		// 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.
		Employee employees[]=new Employee[10];
		employees[0]=new Employee("Peter Smith",4000,40,10);
		employees[1]=new Employee("Mary Smith",4500,30,12);
		employees[2]=new Employee("Tony Stark",3000,35,15);
		employees[3]=new Employee("Mike Tomson",2000,35,25);
		
		employees[4]=new Secretary("Mike Peterson",4200,10,12);
		employees[5]=new Secretary("Julia Clark",3500,15,14);
		employees[6]=new Secretary("Denis Azimov",2500,25,16);
		
		employees[7]=new Secretary("Mary Peterson",1200,15,25);
		employees[8]=new Secretary("Julia Clark",2500,25,25);
		employees[9]=new Secretary("Denis Asi",5500,45,15);
		
		// b. Display all the objects on the screen.
		double sumSalary=0;
		for(int i=0;i<10;i++) {
			System.out.println(employees[i].toString());
			sumSalary+=employees[i].getSalary();
		}
		// c. Calculate, and then display, the average salary of all employees.
		double averageSalary=sumSalary/10.0; 
		System.out.printf("\nThe average salary of all employees: %.2f\n",averageSalary);
		// Extra Calculate and display the cost of the leave to the company for each
		// employee.
		System.out.println("\nThe cost of the leave to the company for each employee:");
		for(int i=0;i<10;i++) {
			double costLeave=(employees[i].getSalary()/employees[i].getHours())*employees[i].getLeaveDays();
			System.out.printf("The cost of the leave to the company for employee %s: %.2f\n",employees[i].getName(),costLeave);
		}
	}
}







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