Employee Management System using Java With Source Code

Employee Management System using Java

Introduction :

Welcome to Employee Management System! It is a simple management tool using java that helps to add employees, view employee details, and remove employees from the system. The system is very handy and works on the admin panel. It is made using java which ensures security at a higher rate. In this new world where all new technologies are overtaking old ones, Java is still surviving and competing with all of them single-handedly. It is one of the most powerful languages,s, especially from a security point of view. Coming back to our employee management system, it is quite easy to use where the admin can add employees on his/her requirements and can view details of employees, and remove employees from the record. The whole process is too easy for the admin which makes this system flexible.

Explanation :

Employee Management System is fully made using the core concepts of java language. It is a system that gives us choices such as – Add Employee, Remove Employee, Display Employees and Exit. We need to import two inbuilt classes where first is Scanner which is used to take input from the user through the keyboard and the second is ArrayList which is part of the collection framework. ArrayList has read-made methods like add and remove which reduces the extra code for our program. Three classes have been made here – 1. Employee 2. EmployeeManagementSystem 3. employeeManagment. Employee class is holding all the necessary getter-setter methods to get and set the employee details like his/her id, age, salary, etc. We have overridden the toString() method in the Employee class to display all the details of the employee in a proper format. In EmployeeManagementSystem class firstly, we have made one object of ArrayList which is further used for adding, displaying, and removing employees. For adding the employee ‘add’ method, removing the employee ‘remove’ method is used with the object of the class. ‘Add’ and ‘Remove’ are the inbuilt methods of ArrayList. For displaying employees, each loop is used which is displaying details of all the employees present in the record. employee management class consists of the main method and switch case where we are calling the respective methods to operate the specific function. For adding an employee, details have been taken and it has been passed to the object of the Employee class. After that simply with the object of EmployeeManagementSystem, we have called the add method. Similarly, the process for removing employees from the system has taken place, the only difference is that process of removal is ID specific. Displaying details of employees is a very easy task, just by calling method displays employee’s details. The last option is for exiting the program which is simply taking place by breaking the loop. Classes, Objects, and ArrayList is the soul of this system. It is quite easy to code and understand this system with having some basic knowledge of OOPS. Happy Coding! 

Source Code

				
					import java.util.ArrayList;
import java.util.Scanner;

class Employee {
  private int id;
  private String name;
  private int age;
  private double salary;

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

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

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

  public int getAge() {
    return age;
  }

  public void setAge(int age) {
    this.age = age;
  }

  public double getSalary() {
    return salary;
  }

  public void setSalary(double salary) {
    this.salary = salary;
  }

  @Override
  public String toString() {
    return "Employee [id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + "]";
  }
}

class EmployeeManagementSystem {
  private ArrayList<Employee> employees = new ArrayList<Employee>();

  public void addEmployee(Employee e) {
    employees.add(e);
  }

  public void removeEmployee(int id) {
    for (int i = 0; i < employees.size(); i++) {
      Employee e = employees.get(i);
      if (e.getId() == id) {
        employees.remove(i);
        break;
      }
    }
  }

  public void displayEmployees() {
    for (Employee e : employees) {
      System.out.println(e);
    }
  }
}

public class employeeManagment {
  public static void main(String[] args) {
    EmployeeManagementSystem ems = new EmployeeManagementSystem();
    Scanner sc = new Scanner(System.in);
    int choice = 0;
    while (choice != 4) {
      System.out.println("1. Add Employee");
      System.out.println("2. Remove Employee");
      System.out.println("3. Display Employees");
      System.out.println("4. Exit");
      System.out.print("Enter your choice: ");
      choice = sc.nextInt();
      sc.nextLine();
      switch (choice) {
        case 1:
          System.out.print("Enter Employee ID: ");
          int id = sc.nextInt();
          sc.nextLine();
          System.out.print("Enter Employee Name: ");
          String name = sc.nextLine();
          System.out.print("Enter Employee Age: ");
          int age = sc.nextInt();
          sc.nextLine();
          System.out.print("Enter Employee Salary: ");
          double salary = sc.nextDouble();
          sc.nextLine();
          Employee e = new Employee(id, name, age, salary);
          ems.addEmployee(e);
          System.out.println("Employee added successfully!");
          break;
          case 2:
          System.out.print("Enter Employee ID to remove: ");
          int removeId = sc.nextInt();
          sc.nextLine();
          ems.removeEmployee(removeId);
          System.out.println("Employee removed successfully!");
          break;
          case 3:
          System.out.println("List of Employees:");
          ems.displayEmployees();
          break;
          case 4:
          System.out.println("Exiting Employee Management System...");
          break;
          default:
          System.out.println("Invalid choice. Try again.");
          break;
          }
          }
          sc.close();
          }
          }
				
			

Find More Projects

Build a Quiz Game Using HTML CSS and JavaScript Introduction Hello coders, you might have played various games, but were you aware …

Emoji Catcher Game Using HTML CSS and JavaScript Introduction Hello Coders, Welcome to another new blog. In this article we’ve made a …

Typing Challenge Using HTML CSS and JavaScript Introduction Hello friends, all you developer friends are welcome to our new project. If you …

Breakout Game Using HTML CSS and JavaScript With Source Code Introduction Hello friends, welcome to today’s new blog post. All of you …

Digital and Analog Clock using HTML CSS and JavaScript Introduction : This project is a digital clock and stopwatch system, which allows …

Coffee Shop Website using HTML, CSS & JavaScript Introduction : This project is a website for coffee house business. It uses HTML …

All Coding Handwritten Notes