0% found this document useful (0 votes)
141 views1 page

csc113 Lab 2

The document provides instructions for creating two Java classes - Employee and Department. The Employee class contains attributes for an employee's id, name, and salary. It includes default and parameterized constructors, as well as getter and setter methods for each attribute and a display method. The Department class models a department that can hold up to 25 Employee objects. It contains arrays for employees and a counter, along with default and additional methods like adding/deleting employees, retrieving employee data, and calculating maximum/average salaries. A main method is included to test the classes.

Uploaded by

Ebtisam Hamed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
141 views1 page

csc113 Lab 2

The document provides instructions for creating two Java classes - Employee and Department. The Employee class contains attributes for an employee's id, name, and salary. It includes default and parameterized constructors, as well as getter and setter methods for each attribute and a display method. The Department class models a department that can hold up to 25 Employee objects. It contains arrays for employees and a counter, along with default and additional methods like adding/deleting employees, retrieving employee data, and calculating maximum/average salaries. A main method is included to test the classes.

Uploaded by

Ebtisam Hamed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 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