-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.java
More file actions
150 lines (115 loc) · 4.24 KB
/
Employee.java
File metadata and controls
150 lines (115 loc) · 4.24 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
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Employee {
private String empName;
private String empId;
private int empSalary;
public Employee() {
}
public Employee(String empNeme, String empId, int empSalary) {
this.empName = empNeme;
this.empId = empId;
this.empSalary = empSalary;
}
public void setEmpName(String empNeme) {
this.empName = empNeme;
}
public void setEmpId(String empId) {
this.empId = empId;
}
public void setEmpSalary(int empSalary) {
this.empSalary = empSalary;
}
public String getEmpName() {
return empName;
}
public String getEmpId() {
return empId;
}
public int getEmpSalary() {
return empSalary;
}
@Override
public String toString() {
return "Employee [empName=" + empName + ", empId=" + empId + ", empSalary=" + empSalary + "]";
}
}
class EmployeeDetail extends Employee {
Scanner sc = new Scanner(System.in);
Map<String, Employee> map = new HashMap<>();
void addEmployee() {
System.out.println("\nEnter Name");
sc.skip("\\R?");
String name = sc.nextLine();
System.out.println("\nEnter Id");
String id = sc.nextLine();
System.out.println("\nEnter Salary");
int salary = sc.nextInt();
Employee employee = new Employee(name, id, salary);
map.put(id, employee);
System.out.println("\nPress ~ to open menu again");
sc.nextLine();
}
void getSingleEmployeeDetail() {
if (map.isEmpty()) {
System.out.println("\nEmployee list is empty 'Please add some details first!'");
} else {
System.out.println("\n\nEnter Employee Id whose detail you want : ");
String id = sc.nextLine();
if (map.containsKey(id)) {
Employee e = map.get(id);
System.out.println("Employee [Employee-Name=" + e.getEmpName() + ", Employee-Id=" + e.getEmpId() + ", Employee-Salary="+ e.getEmpSalary() + "]");
} else {
System.out.println("\nNo such employee exist ");
}
}
System.out.println("\nPress ~ to open menu again");
sc.nextLine();
}
void getAllemployee() {
if (map.isEmpty()) {
System.out.println("\n\nEmployee list is empty 'Please add some details first!'");
} else {
for (Map.Entry<String, Employee> entry : map.entrySet()) {
Employee e = entry.getValue();
System.out.println("Employee [Employee-Name=" + e.getEmpName() + ", Employee-Id=" + e.getEmpId() + ", Employee-Salary="+ e.getEmpSalary() + "]");
}
}
System.out.println("\nPress ~ to open menu again");
sc.nextLine();
}
public static void main(String[] args) {
String input;
Scanner sc = new Scanner(System.in);
EmployeeDetail employeeDetail = new EmployeeDetail();
do {
System.out.println("\nChoose any one ");
System.out.println("1. Add Enployee Details");
System.out.println("2. Get an Employee Details");
System.out.println("3. Get all Employee Details");
System.out.println("4. To Quit");
System.out.println("\nPlease Enter any one : ");
input = sc.nextLine();
switch (input) {
case "1":
employeeDetail.addEmployee();
break;
case "2":
employeeDetail.getSingleEmployeeDetail();
break;
case "3":
employeeDetail.getAllemployee();
break;
case "4":
break;
default:
System.out.println("Please Enter Valid option out of 1 to 4 ");
System.out.println("\nPress ~ to open menu again");
sc.nextLine();
break;
}
} while (!input.equals("4"));
sc.close();
}
}