-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeCollection.java
More file actions
168 lines (138 loc) · 5.77 KB
/
EmployeeCollection.java
File metadata and controls
168 lines (138 loc) · 5.77 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import java.util.*;
class Employee{
private int employee_no;
private String employee_name;
private int employee_salary;
Employee(int employee_no, String employee_name, int employee_salary){
this.employee_no = employee_no;
this.employee_name = employee_name;
this.employee_salary = employee_salary;
}
public int getEmployee_no(){
return employee_no;
}
public String getEmployee_name() {
return employee_name;
}
public int getEmployee_salary() {
return employee_salary;
}
public String toString(){
return employee_no+" "+employee_name+" "+employee_salary;
}
}
class EmployeeCollection{
public static void main(String[] args){
List<Employee> employees = new ArrayList<Employee>();
Scanner getInput = new Scanner(System.in);
Scanner getString = new Scanner(System.in);
int data, eno, esalary;
String ename;
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: ");
data = getInput.nextInt();
System.out.println("");
switch(data){
// INSERT
case 1:
System.out.println("-=-=-=-=-= INSERT EMPLOYEE DATA -=-=-=-=-=");
System.out.print("Enter Employee No: ");
eno = getInput.nextInt();
System.out.print("Enter Employee Name: ");
ename = getString.nextLine();
System.out.print("Enter Employee Salary: ");
esalary = getInput.nextInt();
System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
System.out.println("");
employees.add(new Employee(eno, ename, esalary));
break;
// DISPLAY
case 2:
System.out.println("-=-=-=-=-= DISPLAY EMPLOYEE DATA -=-=-=-=-=");
Iterator<Employee> i = employees.iterator();
while(i.hasNext()){
Employee e = i.next();
System.out.println(e);
}
System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
System.out.println("");
break;
// SEARCH
case 3:
Boolean found = false;
System.out.println("-=-=-=-=-= SEARCH EMPLOYEE DATA -=-=-=-=-=");
System.out.print("Enter Employee No: ");
eno = getInput.nextInt();
i = employees.iterator();
while (i.hasNext()) {
Employee e = i.next();
if(e.getEmployee_no() == eno){
System.out.println(e);
found = true;
}
}
if(!found){
System.out.println("RECORD NOT FOUND!");
}
System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
System.out.println("");
break;
// DELETE
case 4:
found = false;
System.out.println("-=-=-=-=-= DELETE EMPLOYEE DATA -=-=-=-=-=");
System.out.print("Enter Employee No: ");
eno = getInput.nextInt();
i = employees.iterator();
while (i.hasNext()) {
Employee e = i.next();
if(e.getEmployee_no() == eno){
i.remove();
found = true;
}
}
if(!found){
System.out.println("RECORD NOT FOUND!");
} else {
System.out.println("RECORD IS DELETED SUCCESSFULLY!");
}
System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
System.out.println("");
break;
// SEARCH
case 5:
found = false;
System.out.println("-=-=-=-=-= UPDATE EMPLOYEE DATA -=-=-=-=-=");
System.out.print("Enter Employee No. to Update: ");
eno = getInput.nextInt();
ListIterator<Employee> li = employees.listIterator();
while (li.hasNext()) {
Employee e = li.next();
if (e.getEmployee_no() == eno) {
System.out.println("");
System.out.println("Update the following:");
System.out.print("Enter Employee Name: ");
ename = getString.nextLine();
System.out.print("Enter Employee Salary: ");
esalary = getInput.nextInt();
li.set(new Employee(eno, ename, esalary));
found = true;
}
}
if (!found) {
System.out.println("RECORD NOT FOUND!");
} else {
System.out.println("RECORD IS UPDATED SUCCESSFULLY!");
}
System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
System.out.println("");
}
System.out.println("");
}while(data != 0);
}
}