-
Notifications
You must be signed in to change notification settings - Fork 6
/
Auditing.java
81 lines (74 loc) · 1.95 KB
/
Auditing.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
import java.util.ArrayList;
public interface EmployeeAudit {
public ArrayList<String> fetchEmployeeDetails(double salary);
}
//========================================//
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
private static Map <String,Double> employeeMap = new
HashMap<String,Double>();
public Map<String, Double> getEmployeeMap() {
return employeeMap;
}
public void setEmployeeMap(Map<String, Double> employeeMap) {
this.employeeMap = employeeMap;
}
public void addEmployeeDetails(String employeeName, double salary)
{
employeeMap.put(employeeName,salary);
}
public static EmployeeAudit findEmployee()
{
ArrayList<String> name= new ArrayList<String>();
EmployeeAudit employeeAudit = (search)->{
for (Map.Entry<String,Double> i:employeeMap.entrySet() )
if(i.getValue()<=search){
name.add(i.getKey());
}
return name;
};
return employeeAudit;
}
public static void main(String[] args)
{
Main emp = new Main();
Scanner sc=new Scanner(System.in);
int choice=0;
do{
System.out.println("1. Add Employee details");
System.out.println("2. Find Employee details");
System.out.println("3. Exit");
System.out.println("Enter the choice");
choice=Integer.parseInt(sc.nextLine());
switch(choice){
case 1:
System.out.println("Enter the Employee name");
String name=sc.nextLine();
System.out.println("Enter the Employee Salary");
double salary=Double.parseDouble(sc.nextLine());
emp.addEmployeeDetails(name,salary);
break;
case 2:
System.out.println("Enter the salary to be searched");
double search=Double.parseDouble(sc.nextLine());
ArrayList<String>
nameList=findEmployee().fetchEmployeeDetails(search);
if(nameList.isEmpty()){
System.out.println("No employee found");
}
else{
System.out.println("Employee List");
for(String empName: nameList){
System.out.println(empName);
}
}
break;
default:
break;
}}while(choice!=3);
System.out.println("Let's complete the session");
}
}