-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmpManage.java
147 lines (131 loc) · 3.17 KB
/
EmpManage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import java.util.*;
class Employee {
private int empno;
private String empname;
private double salary;
Employee(int empno,String empname,double salary){
this.empno=empno;
this.empname=empname;
this.salary=salary;
}
public int getEmpno(){
return empno;
}
public String getEmpname(){
return empname;
}
public double getSalary(){
return salary;
}
public String toString(){
return empno+" "+empname+" "+salary;
}
}
class EmpManage {
public static void main(String args[]){
List<Employee> c = new ArrayList<Employee>();
Scanner s = new Scanner(System.in);
Scanner s1 = new Scanner(System.in);
Scanner s2 = new Scanner(System.in);
int ch;
do{
System.out.println("1 INSERT");
System.out.println("2 DISPLAY");
System.out.println("3 SEARCH");
System.out.println("4 DELETE");
System.out.println("5 UPDATE");
System.out.print("Enter your choice: ");
ch = s.nextInt();
switch(ch){
case 1:
System.out.print("Enter employee no: ");
int eno = s.nextInt();
System.out.print("Enter employee name: ");
String ename = s1.nextLine();
System.out.print("Enter employee salary: ");
double esalary = s2.nextDouble();
c.add(new Employee(eno,ename,esalary));
System.out.println("-----------------------");
System.out.println("Employee Inserted successfully");
System.out.println("-----------------------");
break;
case 2:
System.out.println("-----------------------");
Iterator<Employee> i = c.iterator();
while(i.hasNext()){
Employee e = i.next();
System.out.println(e);
}
System.out.println("-----------------------");
break;
case 3:
boolean search = false;
System.out.print("Enter employee no: ");
eno = s.nextInt();
i = c.iterator();
while(i.hasNext()){
Employee e = i.next();
if(e.getEmpno()==eno){
search = true;
System.out.println("-----------------------");
System.out.println(e);
}
}
if(!search){
System.out.println("-----------------------");
System.out.println("Employee not found");
}
System.out.println("-----------------------");
break;
case 4:
search = false;
System.out.print("Enter Employee no which you want delete: ");
eno = s.nextInt();
i = c.iterator();
while(i.hasNext()){
Employee e = i.next();
if(e.getEmpno()==eno){
i.remove();
search = true;
}
}
if(!search){
System.out.println("-----------------------");
System.out.println("Employee not found");
}
else {
System.out.println("-----------------------");
System.out.println("Employee Deleted successfully ");
}
System.out.println("-----------------------");
break;
case 5:
search = false;
System.out.print("Enter Employee no which you want update : ");
eno = s.nextInt();
ListIterator<Employee> li = c.listIterator();
while(li.hasNext()){
Employee e = li.next();
if(e.getEmpno()==eno){
System.out.print("Enter employee name: ");
ename = s1.nextLine();
System.out.print("Enter employee salary: ");
esalary = s2.nextDouble();
li.set(new Employee(eno,ename,esalary));
search = true;
}
}
if(!search){
System.out.println("-----------------------");
System.out.println("Employee not found");
}
else {
System.out.println("Employee Updated successfully ");
}
System.out.println("-----------------------");
break;
}
}
while(ch!=0);
}
}