-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElectricityBoardMain.java
More file actions
75 lines (62 loc) · 2.71 KB
/
ElectricityBoardMain.java
File metadata and controls
75 lines (62 loc) · 2.71 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
package med;
import java.util.*;
public class ElectricityBoardMain {
private Map<String, String> electricityMap = new HashMap<>();
public Map<String, String> getElectricityMap() {
return electricityMap;
}
public void setElectricityMap(Map<String, String> electricityMap) {
this.electricityMap = electricityMap;
}
public int findCountOfConnectionsBasedOnTheConnectionType(String connectionType) {
int count = 0;
for (String type : electricityMap.values()) {
if (type.equalsIgnoreCase(connectionType)) {
count++;
}
}
return count == 0 ? -1 : count;
}
public List<String> findConnectionIdsBasedOnTheConnectionType(String connectionType) {
List<String> ids = new ArrayList<>();
for (Map.Entry<String, String> entry : electricityMap.entrySet()) {
if (entry.getValue().equalsIgnoreCase(connectionType)) {
ids.add(entry.getKey());
}
}
return ids;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ElectricityBoardMain eb = new ElectricityBoardMain();
Map<String, String> map = new HashMap<>();
System.out.println("Enter the number of connection records to be added");
int n = Integer.parseInt(sc.nextLine());
System.out.println("Enter the connection records (ConnectionId:Connectiontype)");
for (int i = 0; i < n; i++) {
String[] input = sc.nextLine().split(":");
map.put(input[0], input[1]);
}
eb.setElectricityMap(map);
System.out.println("Enter the Connection type to be searched");
String searchType = sc.nextLine();
int count = eb.findCountOfConnectionsBasedOnTheConnectionType(searchType);
if (count == -1) {
System.out.println("No Connection Ids were found for " + searchType);
} else {
System.out.println("The count of connection Ids based on " + searchType.toUpperCase() + " are " + count);
}
System.out.println("Enter the Connection type to identify the Connection Ids");
String filterType = sc.nextLine();
List<String> ids = eb.findConnectionIdsBasedOnTheConnectionType(filterType);
if (ids.isEmpty()) {
System.out.println("No Connection Ids were found for the " + filterType.toLowerCase());
} else {
System.out.println("Connection Ids based on the " + filterType.toUpperCase() + " are");
for (String id : ids) {
System.out.println(id);
}
}
sc.close();
}
}