-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
192 lines (187 loc) · 5.21 KB
/
Main.java
File metadata and controls
192 lines (187 loc) · 5.21 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package demo1;
import java.util.*;
class Employee
{
private int empNo;
private int empID=0;
private String empName;
private float empSalary;
private String empType;
private String password;
Employee(int empID, int empNo, String empName, float empSalary, String empType, String password)
{
this.empID=empID;
this.empNo = empNo;
this.empName = empName;
this.empSalary = empSalary;
this.empType = empType;
this.password = encrpt(password);
}
String encrpt(String a)
{
String s1="";
char ps[] = a.toCharArray();
for(int i=0;i<ps.length;i++)
s1 = s1 + ++ps[i];
return s1;
}
public int getEmpNo()
{
return empNo;
}
public String getEmpName()
{
return empName;
}
public float getEmpSalary()
{
return empSalary;
}
public String getEmpType()
{
return empType;
}
public String getPassword()
{
String a = password;
String s1="";
char ps[] = a.toCharArray();
for(int i=0;i<ps.length;i++)
s1 = s1 + --ps[i];
return s1;
}
public String toString()
{
return empID+" "+empNo+" "+empName+" "+empSalary+" "+empType+" "+password;
}
}
public class Main {
/**
* @param args
*/
@SuppressWarnings("resource")
public static void main(String[] args)
{
int choice;
Scanner s1 = new Scanner(System.in);
Scanner s2 = new Scanner(System.in);
int empId=0;
List<Employee> list = new ArrayList<Employee>();
Employee e = new Employee(0,999,"Salman",24578.0f,"Admin","salman");
for(;;)
{
System.out.print("Enter Your No :");
int No = s1.nextInt();
System.out.print("Enter Your password :");
String password = s2.nextLine();
if( No == e.getEmpNo() && password.equals(e.getPassword()) )
{
do
{
System.out.println("1. Add Employee data");
System.out.println("2. view Employee data");
System.out.println("3. Search Employee data");
System.out.println("4. Delete Employee Employee data");
System.out.println("5. Update Employee Employee data");
System.out.println("0. To Log Out of the Application");
System.out.print("Enter your choice : ");
Iterator<Employee> itr = list.iterator();
choice =s1.nextInt();
switch(choice)
{
case 1:
System.out.print("Enter Employee No : ");
int empNo = s1.nextInt();
System.out.print("Enter Employee Name : ");
String empName = s2.nextLine();
System.out.print("Enter Employee Salary : ");
float empSalary = s1.nextFloat();
System.out.print("Enter Employee Type : ");
String empType = s2.nextLine();
list.add(new Employee(++empId,empNo, empName, empSalary,empType,empName+empNo));
break;
case 2:
System.out.println("----------------------------------");
while(itr.hasNext())
{
Employee e1 = itr.next();
System.out.println(e1);
}
System.out.println("----------------------------------");
break;
case 3:
System.out.print("Enter the Employee No to be searched :");
int temp=s1.nextInt();
System.out.println("----------------------------------");
int flag=0;
while(itr.hasNext())
{
Employee e1 = itr.next();
if(temp== e1.getEmpNo())
{
System.out.println("Data Found :"+e);
flag=1;
}
}
if(flag==0)
System.out.println("Employee Not Found");
System.out.println("----------------------------------");
break;
case 4:
System.out.print("Enter the Employee No to be deleted :");
int temp1=s1.nextInt();
System.out.println("----------------------------------");
int flag1=0;
while(itr.hasNext())
{
Employee e1 = itr.next();
if(temp1== e1.getEmpNo())
{
itr.remove();
flag1=1;
}
}
if(flag1==0)
System.out.println("Employee Not Found");
else
System.out.println("Employee Data deleted");
System.out.println("----------------------------------");
break;
case 5:
System.out.print("Enter the Employee No to be Updated :");
temp1=s1.nextInt();
System.out.println("----------------------------------");
flag1=0;
ListIterator<Employee> li = list.listIterator();
while(li.hasNext())
{
Employee e1 = li.next();
if(temp1== e1.getEmpNo())
{
System.out.print("Enter Employee Name :");
String name = s2.nextLine();
System.out.print("Enter Employee Salary:");
float salary = s1.nextFloat();
System.out.print("Enter Employee Type :");
String type = s2.nextLine();
li.set(new Employee(empId,temp1,name, salary, type,name+temp1));
flag1=1;
}
}
if(flag1==0)
System.out.println("Employee Not Found");
else
System.out.println("Employee Data Updated");
System.out.println("----------------------------------");
break;
}
}while(choice!=0);
break;
}
else
{
System.out.println("Wrong ID or Password");
}
}
}
}