0% found this document useful (0 votes)
15 views7 pages

Java Employee Management System

The program implements an employee management system with the following features: 1) Adding employee details by creating a file for each employee 2) Viewing employee details by reading the file 3) Removing an employee by deleting their file 4) Updating employee details by replacing text in their file 5) Exiting the program It uses classes, objects, inheritance, polymorphism and exceptions to manage the different features through a menu driven user interface.

Uploaded by

Daniel Shobe
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views7 pages

Java Employee Management System

The program implements an employee management system with the following features: 1) Adding employee details by creating a file for each employee 2) Viewing employee details by reading the file 3) Removing an employee by deleting their file 4) Updating employee details by replacing text in their file 5) Exiting the program It uses classes, objects, inheritance, polymorphism and exceptions to manage the different features through a menu driven user interface.

Uploaded by

Daniel Shobe
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Employee Management System

Problem Statement
Q5: Write a java program to implement “Employee Management System”. In
which you have to include at least three from the given topics as per
requirement of the program: Inheritance, Overriding Methods, Polymorphism,
Abstract Classes, Nested Classes, Interfaces, Lambda Expressions, Exceptional
Handling and I/O Fundamentals. Avoid copying the solutions from any
student/website. Try to implement using the concept covered in the class.
Solution must be unique for each student.

Solution
In this code I have used the concept of Classes and Objects to solve
the problem. I have created a menu for the user which consists of 5
different features.
1. To add an employee
2. To view details of an employee
3. To remove an employee
4. To update info of an employee
5. To exit the Portal.
For each of these features I have created a separate class to maintain
the decorum of the code. Also I have use the concept of Switch Cases
to automate the task and make it more useful and user friendly. User
need to just enter the numbers as per given and it will perform the
task.

CODE

/******************** Importing Essential Libraries


************************/

import [Link].*;
import [Link].*;

/*************************** MENU OF EMS ****************************/

class MainMenu
{
public void menu()
{
[Link]("*******************************************");
[Link]("\t EMPLOYEE MANAGEMENT SYSTEM");
[Link]("*******************************************");
[Link]("\t\t\t--------------------");
[Link]("\t\t\t ~$ Abhinav Dubey");
[Link]("\t\t\t--------------------");
[Link]("\n\nPress 1 : To Add an Employee Details");
[Link]("Press 2 : To See an Employee Details ");
[Link]("Press 3 : To Remove an Employee");
[Link]("Press 4 : To Update Employee Details");
[Link]("Press 5 : To Exit the EMS Portal");

}
}

/************************ To add details of Employee


*********************/

class Employee_Add
{
public void createFile()
{
Scanner sc=new Scanner([Link]);

EmployDetail emp=new EmployDetail();


[Link]();
try{
File f1=new File("file"+emp.employ_id+".txt");
if([Link]()){
FileWriter myWriter = new
FileWriter("file"+emp.employ_id+".txt");
[Link]("Employee ID:"+emp.employ_id+"\
n"+"Employee Name :"+[Link]+"\n"+
"Father's Name :"+emp.father_name+"\n"+"Employee
Contact :"+emp.employ_contact+"\n"+
"Email Information :"+[Link]+"\n"+"Employee position
:"+[Link]+"\n"+
"Employee Salary :"+emp.employ_salary);
[Link]();
[Link]("\nEmployee has been Added :)\n");

[Link]("\nPress Enter to Continue...");


[Link]();
}
else {
[Link]("\nEmployee already exists :(");
[Link]("\nPress Enter to Continue...");
[Link]();
}
}
catch(Exception e){[Link](e);}
}
}

/************************* Taking Employee Details


************************/
class EmployDetail
{
String name;
String father_name;
String email;
String position;
String employ_id;
String employ_salary;
String employ_contact;
public void getInfo()
{
Scanner sc=new Scanner([Link]);
[Link]("Enter Employee's name --------: ");
name=[Link]();
[Link]("Enter Employee's Father name -: ");
father_name=[Link]();
[Link]("Enter Employee's ID ----------: ");
employ_id=[Link]();
[Link]("Enter Employee's Email ID ----: ");
email=[Link]();
[Link]("Enter Employee's Position ----: ");
position=[Link]();
[Link]("Enter Employee contact Info --: ");
employ_contact=[Link]();
[Link]("Enter Employee's Salary ------: ");
employ_salary=[Link]();
}
}

/************************ To Show details of Employee


*********************/

class Employee_Show
{
public void viewFile(String s) throws Exception
{
File file = new File("file"+s+".txt");
Scanner sc = new Scanner(file);

while ([Link]())
{
[Link]([Link]());
}
}
}

/***************************** To Remove Employee


*************************/

class Employee_Remove
{
public void removeFile(String ID)
{

File file = new File("file"+ID+".txt");


if([Link]())
{
if([Link]());
{
[Link]("\nEmployee has been removed
Successfully");
}
}
else
{
[Link]("\nEmployee does not exists :( ");
}
}
}

/************************ To Update details of Employee


********************/

class Employee_Update
{
public void updateFile(String s,String o,String n) throws IOException
{
File file = new File("file"+s+".txt");
Scanner sc = new Scanner(file);
String fileContext="";
while ([Link]())
{
fileContext =fileContext+"\n"+[Link]();
}
FileWriter myWriter = new FileWriter("file"+s+".txt");
fileContext = [Link](o,n);
[Link](fileContext);
[Link]();

}
}

/************************ To Exit from the EMS Portal


*********************/

class CodeExit
{
public void out()
{
[Link]("\n*****************************************");
[Link]("$ cat Thank You For Using my Software :) ");
[Link]("*****************************************");
[Link]("\t\t/~ <0d3d by Abhinav Dubey\n");
[Link](0);
}
}

/***************************** Main Class


*******************************/
class EmployManagementSystem
{
public static void main(String arv[])
{
/** To clear the output Screen **/
[Link]("\033[H\033[2J");

Scanner sc=new Scanner([Link]);


Employee_Show epv =new Employee_Show();

int i=0;

/*** Callining Mainmenu Class function ****/


MainMenu obj1 = new MainMenu();
[Link]();

/*** Initialising loop for Menu Choices ***/


while(i<6)
{

[Link]("\nPlease Enter choice :");


i=[Link]([Link]());

/** Switch Case Statements **/


switch(i)
{
case 1:
{
/** Creating class's object and calling Function using that
object **/
Employee_Add ep =new Employee_Add();
[Link]();

[Link]("\033[H\033[2J");
[Link]();
break;
}
case 2:
{
[Link]("\nPlease Enter Employee's ID :");
String s=[Link]();
try
{
[Link](s);}
catch(Exception e){[Link](e);}

[Link]("\nPress Enter to Continue...");


[Link]();
[Link]("\033[H\033[2J");
[Link]();
break;
}

case 3:
{
[Link]("\nPlease Enter Employee's ID :");
String s=[Link]();
Employee_Remove epr =new Employee_Remove();
[Link](s);

[Link]("\nPress Enter to Continue...");


[Link]();
[Link]("\033[H\033[2J");
[Link]();
break;
}
case 4:
{
[Link]("\nPlease Enter Employee's ID :");
String I=[Link]();
try
{
[Link](I);
}
catch(Exception e)
{
[Link](e);
}
Employee_Update epu = new Employee_Update();
[Link]("Please Enter the detail you want to
Update :");
[Link]("\nFor Example :\n");
[Link]("If you want to Change the Name, then
Enter Current Name and Press Enter. Then write the new Name then Press
Enter. It will Update the Name.\n");
String s=[Link]();
[Link]("Please Enter the Updated Info :");
String n=[Link]();
try
{
[Link](I,s,n);

[Link]("\nPress Enter to Continue...");


[Link]();
[Link]("\033[H\033[2J");
[Link]();
break;
}
catch(IOException e)
{
[Link](e);
}
}
case 5:
{
CodeExit obj = new CodeExit();
[Link]();
}
}
}
}
}
OUTPUT SCREENSHOTS

Submitted By : Abhinav Dubey


Section : K18QW
Roll No. : 41
Reg. No. : 11803384

Common questions

Powered by AI

The system uses I/O fundamentals by employing the File class for data storage and retrieval, interfacing with text files to store each employee's details individually. This method is straightforward but may not scale well for larger datasets due to inefficiencies in handling numerous file I/O operations. Alternative approaches include using a database management system (DBMS) that offers better query performance, transaction management, and scalability, or employing data serialization techniques such as JSON or XML for more efficient data handling .

Modularity is significant in this system's design as it promotes organized, maintainable, and scalable code. The design achieves modularity by breaking down functionalities into distinct classes, each responsible for specific operations like adding, viewing, removing, and updating employees. This separation of concerns allows for easier management and potential future expansion of the system, as changes or enhancements to one component are less likely to impact others adversely .

The system uses the File class to create and manage files storing employee details. When adding an employee, it checks if a file with the employee's ID already exists to avoid duplicates. The system uses FileWriter to write employee details to a new file if it does not already exist. For viewing, it retrieves data using a Scanner object to read from the existing file. When updating, it reads the file’s content and replaces specified old data with new data before writing back the updated content using FileWriter .

Exception handling in the Employee Management System is used to manage potential errors related to file operations. For example, when viewing or updating employee details, try-catch blocks handle IOExceptions or general exceptions. This prevents the program from crashing due to unforeseen errors, such as file not found errors when attempting to read a file or IO errors when writing to a file .

The system offers basic functionalities but can be considered lacking in robustness due to its reliance on file handling without robust error checking, data validation, and lack of concurrency control mechanisms. The system could be vulnerable to data integrity issues and may not handle concurrent user updates efficiently. To enhance robustness, implementing data validation, transitioning to a relational database, and incorporating concurrency control measures are vital improvements needed .

The program implements a structured menu system using the MainMenu class to enhance user interaction. This menu guides the user through available options like adding, viewing, and removing employee details. The system uses a switch-case mechanism to automate responses based on the user's input choice (such as entering 1, 2, 3, etc.). This automated response simplifies user commands and operations, thereby enhancing user-friendliness. Additionally, it repeatedly prompts the user for input, making processes streamlined and reducing the need for manual navigation .

The Employee Management System (EMS) utilizes object-oriented principles by employing classes and objects to perform different functionalities. For instance, separate classes such as Employee_Add, Employee_Show, Employee_Remove, and Employee_Update handle specific tasks related to managing employees. While the document does not explicitly mention inheritance, the system's usage of distinct classes shows encapsulation and indirectly allows for potential inheritance if subclasses were to be derived. Polymorphism could be present through method overriding if subclasses or interfaces were introduced, as suggested by requiring the implementation of inheritance, polymorphism, or other designated Java features .

Lambda Expressions could simplify the syntax for defining functional interfaces, potentially reducing boilerplate when implementing actions like handling menu choices or performing I/O operations. Interfaces could enhance the design by providing a contract for employee operations, allowing different classes to implement standardized methods for actions such as add, view, update, and remove. This would promote a more flexible architecture where new implementations could be easily substituted .

To address the limitations of plain text files, such as lack of transaction management, poor query capabilities, and inefficiency in data retrieval, transitioning to a database system like MySQL or SQLite could vastly improve data management. These databases offer enhanced capabilities like indexing, which improves search speed, and support for complex queries and data integrity constraints. Implementing a database would also facilitate easier data updates and consistency through structured query language (SQL).

The system currently does not implement explicit data validation for employee data inputs like employee ID, email, or contact information beyond checking file existence for duplicate IDs. This lack of validation could lead to issues with incorrect data being stored, overlapping IDs if IDs are input erroneously, or inconsistencies in contact and email formats. Implementing validation logic would improve data integrity and reliability, ensuring that all input data meets predefined criteria before being accepted .

You might also like