Employee Management Data System.

NOTE: If you are copying my code then its a advise to you to copy it after downloading it to avoid any kind of compilation error its link is available at the bottom of source code.




It's been a long I haven't posted anything so without wasting time let's proceed to the main point. Actually I have created a program that will manage the data of employee for a company. It's a simple program but it will help to the beginner to understand the concept making function, calling function and creating object.

What my code actually do?

So, Here I have given few option to the user that are as follows

1. Insert Data
2. Display Data
3. Manage Data(update)

Insert Data

If your will select this option then It will ask you 3 things that are as follows

  • Employee ID
  • Employee Name
  • Employee Salary
Here i have given limited ob basic option to user but if you want to add anything you can do by your own 

Display Data

When you select this option then it will give you 5 sub option that are as follows

  • Search Employee By its Name
  • Search Employee By its Id
  • Display Name in sorted order
  • Display Id in sorted order
  • Display All record

Manage Data(Updation)

This option will give the feature to update the name and salary of a particular employee all you have to do is to provide the employee id that you looking for updation.



I hope that It help you understand the basic concept of calling function and all other stuff.


Advice

its my advice to run this program in cmd it you don't know how deal java programming with command prompt then read read the following page carefully

Click here to understand How work with java and Its path setup
Click here to understand how to make program through notepad and how compile and run java program



SOURCE CODE


import java.util.*;
class Employee{
int empId;
String name;
float salary;
static int check=0;

void inputEmployee(int count,Employee emp[]){
Scanner sc=new Scanner(System.in);
System.out.print("Enter Employee ID :");
int id1=sc.nextInt();
int flag = 0;
check=0;
for(int i=0;i<count;i++)
{
if(id1 == emp[i].empId)
{
System.out.println("Id already exists");
flag=1;
check=flag;
break;
}
}
if(flag==0)
{
empId=id1;
System.out.print("Enter Employee Name :");
sc.nextLine();
name=sc.nextLine();
System.out.print("Enter Employee Salary :");
salary=sc.nextFloat();
System.out.println("Data has been inserted successfully");
}
}

void updateEmployee(int id,Employee emp[],int count){
Scanner sc=new Scanner(System.in);
int flag=0;
for(int i=0;i<count;i++){
if(emp[i].empId==id){
System.out.print("Enter Name :");
emp[i].name=sc.nextLine();
System.out.print("Enter salary :");
emp[i].salary=sc.nextFloat();
flag=1;
}
}
if(flag==0)
{
System.out.println("Id not found!!!");
}
}

void SortEmployeeByName(Employee[] emp,int count){
for(int i=0;i<count-1;i++){
for(int j=0;j<count-i-1;j++){
if(emp[j].name.compareTo(emp[j+1].name)>0){
Employee ob=new Employee();
ob=emp[j];
emp[j]=emp[j+1];
emp[j+1]=ob;
}
}
}
}


void Display(Employee emp[],int count){
int flag=0;
for(int i=0;i<count;i++){
System.out.print(emp[i].empId+"\t\t"+emp[i].name+"\t\t"+emp[i].salary+"\n");

}
}

void DisplayByName(Employee emp[],String name1, int count){
int flag=0;
for(int i=0;i<count;i++){
if((emp[i].name).equals(name1)){
System.out.print(emp[i].empId+"\t\t"+emp[i].name+"\t\t"+emp[i].salary+"\n");
flag=1;
}
}
if(flag==0)
System.out.println("Record Not found!!");
}

void DisplayByID(Employee emp[],int id,int count){
for(int i=0;i<count;i++)
{
if(emp[i].empId==id)
System.out.print(emp[i].empId+"\t"+emp[i].name+"\t"+emp[i].salary+"\n");
}
}

void DisplayBysortedID(Employee emp[],int count){
for(int i=0;i<count-1;i++){
for(int j=0;j<count-i-1;j++){
if(emp[j].empId>(emp[j+1].empId)){
Employee ob=new Employee();
ob=emp[j];
emp[j]=emp[j+1];
emp[j+1]=ob;
}
}
}
}
}

class empData{
public static void clearscreen(){
try{
new ProcessBuilder("cmd","/c","cls").inheritIO().start().waitFor();
}
catch(Exception e){
}
}

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
clearscreen();
char c='y';
int count=0;
Employee ob=new Employee();
Employee emp[]=new Employee[50];
while(c=='y'||c=='Y'){
clearscreen();
System.out.println("\t\t\t\tWELCOME TO EMPLOYEE MANAGEMENT DATA SYSTEM\n\n");
System.out.println("Press 1 to Intert Employee Rocord");
System.out.println("Press 2 to Display Employee Record");
System.out.println("Press 3 to update Employee Record");
System.out.println("Press 4 to Exit");
System.out.println("\t\t\tEnter Your Choice");
int n=sc.nextInt();
switch(n)
{
case 1:
emp[count]=new Employee();
emp[count].inputEmployee(count,emp);
if(Employee.check==1)
count--;
count++;
break;

case 2:
char ch='y';
do
{
clearscreen();
System.out.println("Press 1 to Display Data by searching name");
System.out.println("Press 2 to Display Data by searching id");
System.out.println("Press 3 to display data in soted manner by name");
System.out.println("Press 4 to Display Data in soted manner by ID");
System.out.println("Press 5 to Display All data");
System.out.println("\t\t\t Enter Your Choice ");
int d=sc.nextInt();
sc.nextLine();
switch(d)
{
case 1:
System.out.println("Enter name that you want to search");
String name=sc.nextLine();
System.out.println("\t\tSearched name is given below");
System.out.println("ID\t\tName\t\tSalary");
ob.DisplayByName(emp,name,count);break;
case 2:
System.out.println("Enter ID that you want to search");
int id=sc.nextInt();
System.out.println("ID\t\tName\t\tSalary");
ob.DisplayByID(emp,id,count);
break;
case 3:
ob.SortEmployeeByName(emp,count);
System.out.println("ID\t\tName\t\tSalary");
ob.Display(emp,count);
break;
case 4:
System.out.println("ID\t\tName\t\tSalary");
ob.DisplayBysortedID(emp,count);
ob.Display(emp,count);
break;
case 5:
System.out.println("ID\t\tName\t\tSalary");
ob.Display(emp,count);
break;
default:
System.out.println("Invalid Choice");
}
System.out.print("Press E/e to exit this menu or any key to continue :");
ch=sc.next().charAt(0);
}while(ch!='e' && ch!='E');
break;
case 3:
System.out.println("Enter Id to update info");
int id=sc.nextInt();
ob.updateEmployee(id, emp,count);
break;
case 4:
c='n';

}
if(c=='n')break;
System.out.println("press y/Y to continue");
c=sc.next().charAt(0);

}
}
}



Click here to Download




If you have any question then leave a comment below I will do my best to answer that question.


Comments

Popular posts from this blog

[Question 3] ISC 2017 Computer Practical Paper Solved – Caesar Cipher.

Pattern of your own name.

Designing Patterns - Print 'Z'.