Employees System

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Employee Class:

• The Employee class represents an employee with private fields for their ID, first name, last
name, email, phone number, and salary.
• It has a constructor that initializes these fields when a new Employee object is created.
• Getter methods are provided to access the private fields.

EmployeeSystem Class:

• The EmployeeSystem class manages a list of Employee objects using an ArrayList.


• It has a constructor that initializes the list of employees.
• The addEmployee(Employee employee) method adds an employee to the list.
• The getEmployeeById(int employeeId) method searches for an employee by their ID and returns
the corresponding Employee object. If not found, it returns null.
• The getAllEmployees() method returns a copy of the list of all employees.

Main Class (public class Main):

• In the main method:

• An instance of EmployeeSystem called employeeSystem is created.


• Sample employees are added to the system using the addEmployee method.
• Employee details are displayed in a tabular format:
❖ A header row is printed using System.out.printf to create a professional-looking table.
❖ A loop iterates through all employees using employeeSystem.getAllEmployees().
❖ For each employee, their details are printed in a formatted row using System.out.printf.
• A footer row is printed to complete the table.

Output Formatting:

• The output is formatted in a tabular layout using the System.out.printf statements to display
employee details in a clear and organized way.
• The %10s, %15s, and %10.2f are format specifiers specifying the width and precision of the
printed values.

Execution:

• When the program is executed, it creates an instance of EmployeeSystem, adds sample


employees, and prints their details in a well-formatted table.

In summary, this Java program demonstrates a simple employee management system where employees
are represented as objects of the Employee class, and the EmployeeSystem class manages a list of these
employees. The main method adds sample employees, and then it prints their details in a formatted
table.

You might also like