You are on page 1of 1

King Saud University Department of Computer Science

College of Computer & Information Science CSC 113

Lab 2
Create a class called Employee with the following attributes:
 id of type int
 name of type String
 salary of type double

Add the following constructors to Employee:


 Default constructor Employee() that initializes id with the value 0, name with “NONAME”
and salary with 0.0
 Constructor with parameters: Employee(int employeeId, String employeeName, double
employeeSalary)

Add the following methods to Employee:


 public int getId(): Returns the id of an employee
 public String getName(): Returns the name of an employee
 public double getSalary(): Returns the salary of an employee
 public void setId(int employeeId): Sets the id of an employee
 public void setName(String employeeName): Sets the name of an employee
 public void setSalary(double employeeSalary): Sets the salary of an employee
 public void display(): Displays an employee's id, name and salary

Suppose a department can hold up to 25 employees, create a class called Department with the
following attributes:
 employees of type Employee[]
 employeeCounter of type int

Add the following constructor to Department:


 Default constructor Department() that initializes employees with 25 Employee objects and
employeeCounter with 0

Add the following methods to Department:


 public String getName(int employeeId): Returns the name of the employee with given id
 public double getSalary(int employeeId): Returns the salary of the employee with given id
 public int getEmployeeCount(): Returns the number of current employees
 public void display(): Displays all employees in the department
 public boolean addEmployee(int employeeId, String employeeName, double
employeeSalary): Adds an employee with given id, name and salary to the end of
employees, it returns true in case success and false in case of failure
 public boolean deleteEmployee(int employeeId): Deletes the employee with given id from
employees, it returns true in case of success and false in case of failure
 public int maxSalary(): Returns the id of employee with maximum salary
 public double averageSalary(): Returns the average salary of all employees in the
department
 public static void main(String args[]): Tests the above methods

You might also like