An Employee Management System (EMS) is an application used to store, organize, and manage employee information efficiently. In this Java project, we will build a simple Employee Management System that allows users to perform basic operations on employee records.
- Users can add, search, view, and delete employee records.
- Each employee record stores information such as name, employee ID, designation, experience, and age.
Objectives of the Employee Management System
The main objectives of this project are to:
- Create and display employee records.
- Insert new employee records.
- Search for an employee using the employee ID.
- Delete existing employee records.
Employee Data
Each employee record contains the following information:
- Name
- Employee ID
- Designation
- Experience
- Age
Approach
The Employee Management System uses an array of Employee objects to store and manage employee records. Each object contains details such as the employee's name, ID, designation, experience, and age.
- Create Employee Class: Define an Employee class containing fields for name, employeeId, designation, experience, and age.
- Build Employee Records: Create an array of Employee objects and initialize each object before storing employee information.
- Insert a Record: Create a new Employee object and store it at the next available position in the array.
- Delete a Record: Search for the employee using the employee ID. After finding the record, shift the subsequent array elements one position to the left and decrease the number of stored records.
- Search a Record: Traverse the employee array and compare the given employee ID with the stored IDs. If a matching record is found, display that employee's complete information.
Employee[] employees = new Employee[20];
employees[i] = new Employee();
employees[i].name = "GeeksforGeeks";
employees[i].employeeId = 12345L;
employees[i].designation = "Developer";
employees[i].experience = 10;
employees[i].age = 30;
#include <bits/stdc++.h>
using namespace std;
#define MAX 20
// Structure of Employee
struct employee {
string name;
long int code;
string designation;
int exp;
int age;
};
employee emp[MAX];
int num = 0;
// Function declarations
void showMenu();
bool isDuplicate(long int code);
// Check duplicate ID
bool isDuplicate(long int code) {
for (int i = 0; i < num; i++) {
if (emp[i].code == code) {
return true;
}
}
return false;
}
// Build initial table
void build() {
cout << "Build The Table\n";
cout << "Maximum Entries can be " << MAX << "\n";
cout << "Enter number of entries: ";
cin >> num;
if (num > MAX) {
cout << "Max limit is " << MAX << ". Setting to max.\n";
num = MAX;
}
for (int i = 0; i < num; i++) {
cout << "\nEmployee " << i + 1 << "\n";
cout << "Employee ID: ";
cin >> emp[i].code;
// Duplicate check
if (isDuplicate(emp[i].code)) {
cout << "Duplicate ID! Try again.\n";
i--;
continue;
}
cout << "Name: ";
cin >> emp[i].name;
cout << "Designation: ";
cin >> emp[i].designation;
cout << "Experience: ";
cin >> emp[i].exp;
cout << "Age: ";
cin >> emp[i].age;
}
}
// Insert new employee
void insert() {
if (num >= MAX) {
cout << "Employee Table Full\n";
return;
}
long int code;
cout << "Enter Employee ID: ";
cin >> code;
if (isDuplicate(code)) {
cout << "Error: Employee ID already exists!\n";
return;
}
emp[num].code = code;
cout << "Name: ";
cin >> emp[num].name;
cout << "Designation: ";
cin >> emp[num].designation;
cout << "Experience: ";
cin >> emp[num].exp;
cout << "Age: ";
cin >> emp[num].age;
num++;
cout << "Employee Added Successfully!\n";
}
// Delete helper
void deleteIndex(int index) {
for (int i = index; i < num - 1; i++) {
emp[i] = emp[i + 1];
}
}
// Delete record
void deleteRecord() {
long int code;
cout << "Enter Employee ID to delete: ";
cin >> code;
for (int i = 0; i < num; i++) {
if (emp[i].code == code) {
deleteIndex(i);
num--;
cout << "Record Deleted Successfully!\n";
return;
}
}
cout << "Employee ID not found!\n";
}
// Search record
void searchRecord() {
long int code;
cout << "Enter Employee ID to search: ";
cin >> code;
for (int i = 0; i < num; i++) {
if (emp[i].code == code) {
cout << "\nEmployee Found:\n";
cout << "Name: " << emp[i].name << "\n";
cout << "ID: " << emp[i].code << "\n";
cout << "Designation: " << emp[i].designation << "\n";
cout << "Experience: " << emp[i].exp << "\n";
cout << "Age: " << emp[i].age << "\n";
return;
}
}
cout << "Employee not found!\n";
}
// Menu
void showMenu() {
int option;
do {
cout << "\n------ Employee Management System ------\n";
cout << "1. Build Table\n";
cout << "2. Insert New Entry\n";
cout << "3. Delete Entry\n";
cout << "4. Search Record\n";
cout << "5. Exit\n";
cout << "Enter option: ";
cin >> option;
switch (option) {
case 1: build(); break;
case 2: insert(); break;
case 3: deleteRecord(); break;
case 4: searchRecord(); break;
case 5: cout << "Exiting...\n"; break;
default: cout << "Invalid option!\n";
}
} while (option != 5);
}
// Driver
int main() {
showMenu();
return 0;
}
/*package whatever //do not write package name here */
import java.util.*;
class GFG {
// Class of Employee
static class employee{
String name;
long code;
String designation;
int exp;
int age;
}
static int num;
static int max = 20;
// Array of Employees to store the
// data in the form of the Structure
// of the Array
static employee emp[] = new employee[max];
static employee tempemp[] = new employee[max];
static employee sortemp[] = new employee[max];
static employee sortemp1[] = new employee[max];
static Scanner sc = new Scanner(System.in);
// Function to build the given datatype
static void build()
{
System.out.println("Build The Table\n");
System.out.println("Maximum Entries can be " + max);
System.out.println("Enter the number of " + "Entries required");
num = sc.nextInt();
if (num > 20) {
System.out.println("Maximum number of "+"Entries are 20");
num = 20;
}
System.out.println("Enter the following data:");
for (int i = 0; i < num; i++) {
System.out.print("Name ");
emp[i].name = sc.next();
System.out.print("Employee ID ");
emp[i].code = sc.nextLong();
System.out.print("Designation ");
emp[i].designation = sc.next();
System.out.print("Experience ");
emp[i].exp = sc.nextInt();
System.out.print("Age ");
emp[i].age = sc.nextInt();
}
showMenu();
}
// Function to insert the data into
// given data type
static void insert()
{
if (num < max) {
int i = num;
num++;
System.out.print("Enter the information " + "of the Employee");
System.out.print("Name ");
emp[i].name = sc.next();
System.out.print("Employee ID ");
emp[i].code = sc.nextLong();
System.out.print("Designation ");
emp[i].designation = sc.next();
System.out.print("Experience ");
emp[i].exp = sc.nextInt();
System.out.print("Age ");
emp[i].age = sc.nextInt();
}
else {
System.out.println("Employee Table Full");
}
showMenu();
}
// Function to delete record at index i
static void deleteIndex(int i)
{
for (int j = i; j < num - 1; j++) {
emp[j].name = emp[j + 1].name;
emp[j].code = emp[j + 1].code;
emp[j].designation = emp[j + 1].designation;
emp[j].exp = emp[j + 1].exp;
emp[j].age = emp[j + 1].age;
}
return;
}
// Function to delete record
static void deleteRecord()
{
System.out.println("Enter the Employee ID "+ "to Delete Record");
int code = sc.nextInt();
for (int i = 0; i < num; i++) {
if (emp[i].code == code) {
deleteIndex(i);
num--;
break;
}
}
showMenu();
}
static void searchRecord()
{
System.out.println("Enter the Employee"+" ID to Search Record");
int code = sc.nextInt();
for (int i = 0; i < num; i++) {
// If the data is found
if (emp[i].code == code) {
System.out.println("Name " + emp[i].name);
System.out.println("Employee ID " + emp[i].code);
System.out.println("Designation " + emp[i].designation);
System.out.println("Experience " + emp[i].exp);
System.out.println("Age " + emp[i].age);
break;
}
}
showMenu();
}
// Function to show menu
static void showMenu()
{
System.out.println("-------------------------"
+ "GeeksforGeeks Employee"
+ " Management System"
+ "-------------------------\n");
System.out.println("Available Options:\n");
System.out.print("Build Table (1)\n");
System.out.print("Insert New Entry (2)\n");
System.out.print("Delete Entry (3)\n");
System.out.print("Search a Record (4)\n");
System.out.print("Exit (5)\n");
int option = sc.nextInt();
// Input Options
// Call function on the basis of the
// above option
if (option == 1) {
build();
}
else if (option == 2) {
insert();
}
else if (option == 3) {
deleteRecord();
}
else if (option == 4) {
searchRecord();
}
else if (option == 5) {
return;
}
else {
System.out.println("Expected Options" + " are 1/2/3/4/5");
showMenu();
}
}
public static void main (String[] args) {
showMenu();
}
}
// This code is contributed by aadityaburujwale.
max = 20
# Structure of Employee
class employee:
def __init__(self):
self.name = ''
self.code = 0
self.designation = ''
self.exp = 0
self.age = 0
num = 0
emp = [employee() for i in range(max)]
tempemp = [employee() for i in range(max)]
sortemp = [employee() for i in range(max)]
sortemp1 = [employee() for i in range(max)]
# Function to build the given datatype
def build():
global num, emp
print("Build The Table")
print("Maximum Entries can be", max)
num = int(input("Enter the number of Entries required: "))
if num > max:
print("Maximum number of Entries are 20")
num = 20
print("Enter the following data:")
for i in range(num):
emp[i].name = input("Name: ")
emp[i].code = int(input("Employee ID: "))
emp[i].designation = input("Designation: ")
emp[i].exp = int(input("Experience: "))
emp[i].age = int(input("Age: "))
showMenu()
# Function to insert the data into
# given data type
def insert():
global num, emp
if num < max:
i = num
num += 1
print("Enter the information of the Employee:")
emp[i].name = input("Name: ")
emp[i].code = int(input("Employee ID: "))
emp[i].designation = input("Designation: ")
emp[i].exp = int(input("Experience: "))
emp[i].age = int(input("Age: "))
else:
print("Employee Table Full")
showMenu()
# Function to delete record at index i
def deleteIndex(i):
global num, emp
for j in range(i, num - 1):
emp[j].name = emp[j + 1].name
emp[j].code = emp[j + 1].code
emp[j].designation = emp[j + 1].designation
emp[j].exp = emp[j + 1].exp
emp[j].age = emp[j + 1].age
# Function to delete record
def deleteRecord():
global num, emp
code = int(input("Enter the Employee ID to Delete Record: "))
for i in range(num):
if emp[i].code == code:
deleteIndex(i)
num -= 1
break
showMenu()
def searchRecord():
global num, emp
code = int(input("Enter the Employee ID to Search Record: "))
for i in range(num):
# If the data is found
if emp[i].code == code:
print("Name:", emp[i].name)
print("Employee ID:", emp[i].code)
print("Designation:", emp[i].designation)
print("Experience:", emp[i].exp)
print("Age:", emp[i].age)
break
showMenu()
# Function to show menu
def showMenu():
print("-------------------------GeeksforGeeks Employee Management System-------------------------\n")
print("Available Options:\n")
print("Build Table (1)")
print("Insert New Entry (2)")
print("Delete Entry (3)")
print("Search a Record (4)")
print("Exit (5)")
# Input Options
option = int(input())
# Call
if option == 1:
build()
elif option == 2 :
insert()
elif option == 3 :
deleteRecord()
elif option == 4 :
searchRecord()
elif option == 5 :
return
else:
print("Expected Options")
print("are 1/2/3/4/5")
showMenu()
# Driver code
showMenu()
// JavaScript program for the above approach
const max = 20;
// Structure of Employee
const employee = {
name: "",
code: 0,
designation: "",
exp: 0,
age: 0
};
let num;
// Array of Employees to store the
// data in the form of the Structure
// of the Array
let emp = new Array(max);
let tempemp = new Array(max);
let sortemp = new Array(max);
let sortemp1 = new Array(max);
// Function to build the given datatype
function build () {
console.log("Build The Table");
console.log("Maximum Entries can be " + max);
console.log("Enter the number of Entries required");
num = prompt();
if (num > 20) {
console.log("Maximum number of Entries are 20");
num = 20;
}
console.log("Enter the following data:");
for (let i = 0; i < num; i++) {
console.log("Name ");
emp[i].name = prompt();
console.log("Employee ID ");
emp[i].code = prompt();
console.log("Designation ");
emp[i].designation = prompt();
console.log("Experience ");
emp[i].exp = prompt();
console.log("Age ");
emp[i].age = prompt();
}
showMenu();
}
// Function to insert the data into
// given data type
function insert() {
if (num < max) {
let i = num;
num++;
console.log("Enter the information of the Employee");
console.log("Name ");
emp[i].name = prompt();
console.log("Employee ID ");
emp[i].code = prompt();
console.log("Designation ");
emp[i].designation = prompt();
console.log("Experience ");
emp[i].exp = prompt();
console.log("Age ");
emp[i].age = prompt();
}
else {
console.log("Employee Table Full");
}
showMenu();
}
// Function to delete record at index i
function deleteIndex (i) {
for (let j = i; j < num - 1; j++) {
emp[j].name = emp[j + 1].name;
emp[j].code = emp[j + 1].code;
emp[j].designation = emp[j + 1].designation;
emp[j].exp = emp[j + 1].exp;
emp[j].age = emp[j + 1].age;
}
return;
}
// Function to delete record
function deleteRecord() {
console.log("Enter the Employee ID to Delete Record");
let code = prompt();
for (let i = 0; i < num; i++) {
if (emp[i].code == code) {
deleteIndex(i);
num--;
break;
}
}
showMenu();
}
function searchRecord() {
console.log("Enter the Employee ID to Search Record");
let code = prompt();
for (let i = 0; i < num; i++) {
// If the data is found
if (emp[i].code == code) {
console.log("Name " + emp[i].name);
console.log("Employee ID " + emp[i].code);
console.log("Designation " + emp[i].designation);
console.log("Experience " + emp[i].exp);
console.log("Age " + emp[i].age);
break;
}
}
showMenu();
}
// Function to show menu
function showMenu() {
console.log("-------------------------" +
"GeeksforGeeks Employee" +
" Management System" +
"-------------------------\n\n");
console.log("Available Options:\n\n");
console.log("Build Table (1)\n");
console.log("Insert New Entry (2)\n");
console.log("Delete Entry (3)\n");
console.log("Search a Record (4)\n");
console.log("Exit (5)\n");
let option = prompt();
// Call function on the basis of the
// above option
if (option == 1) {
build();
} else if (option == 2) {
insert();
} else if (option == 3) {
deleteRecord();
} else if (option == 4) {
searchRecord();
} else if (option == 5) {
return;
} else {
console.log("Expected Options are 1/2/3/4/5");
showMenu();
}
}
// Driver Code
function main() {
showMenu();
return 0;
}
// This code is contributed by akashish__
Output: Below is the output of the above program: 