-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackathon2.java
More file actions
127 lines (107 loc) · 3.58 KB
/
Hackathon2.java
File metadata and controls
127 lines (107 loc) · 3.58 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
import java.util.*;
public class Hackathon2 {
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
DepartmentalStores[]arr = new DepartmentalStores[4];
for(int i =0; i<arr.length; i++){
String a = sc.nextLine();
String b = sc.nextLine();
String c = sc.nextLine();
int d = sc.nextInt();
int e = sc.nextInt();
sc.nextLine();
arr[i] = new DepartmentalStores(a, b, c, d, e);
}
String startsWithInput = sc.nextLine();
String location = sc.nextLine();
int ans = findAverageWorkersInSpecificLocation(arr, startsWithInput);
if(ans>0){
System.out.println(ans);
}else{
System.out.println("No stores are available with the given input");
}
DepartmentalStores[]ans2 = findStoreDetailsForGivenLocation(arr, location);
if(ans2!=null){
for (int i = 0; i < ans2.length; i++) {
System.out.println(ans2[i].getStoreName());
}
}else{
System.out.println("No stores present in the given location");
}
}
public static int findAverageWorkersInSpecificLocation(DepartmentalStores [] arr, String startsWithInput){
int sum =0;
int count=0;
for(int i =0; i<arr.length; i++){
if(arr[i].getStoreId().startsWith(startsWithInput)){
sum+=arr[i].getNumberOfWorkers();
count++;
}
}
return sum/count;
}
public static DepartmentalStores[] findStoreDetailsForGivenLocation(DepartmentalStores[]arr, String location){
int j =0;
DepartmentalStores[]temp = new DepartmentalStores[arr.length];
for(int i =0; i<arr.length; i++){
if(arr[i].getLocation().equalsIgnoreCase(location)){
temp[j++] = arr[i];
}
}
if (j==0) return null;
DepartmentalStores[] result = new DepartmentalStores[j];
for (int i = 0; i < j; i++) {
result[i] = temp[i];
}
Arrays.sort(result, new Comparator<DepartmentalStores>() {
public int compare(DepartmentalStores s1, DepartmentalStores s2) {
return s1.getRating() - s2.getRating();
}
});
return result;
}
}
class DepartmentalStores{
private String storeId;
private String storeName;
private String location;
private int numberOfWorkers;
private int rating;
public DepartmentalStores(String storeId ,String storeName, String location, int numberOfWorkers ,int rating){
this.storeId = storeId;
this.storeName = storeName;
this.location = location;
this.numberOfWorkers = numberOfWorkers;
this.rating = rating;
}
public String getStoreId(){
return storeId;
}
public void setStoreId(String storeId){
this.storeId = storeId;
}
public String getStoreName(){
return storeName;
}
public void setStoreName(String storeName){
this.storeName = storeName;
}
public String getLocation(){
return location;
}
public void setLocation(String location){
this.location = location;
}
public int getNumberOfWorkers(){
return numberOfWorkers;
}
public void setNumberOfWorkers(int numberOfWorkers){
this.numberOfWorkers = numberOfWorkers;
}
public int getRating(){
return rating;
}
public void setRating(int rating){
this.rating = rating;
}
}