-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventoryProblem.java
More file actions
65 lines (53 loc) · 1.88 KB
/
InventoryProblem.java
File metadata and controls
65 lines (53 loc) · 1.88 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
import java.util.*;
class Inventory {
String inventoryId;
int maximumQuantity;
int currentQuantity;
int threshold;
public Inventory(String inventoryId, int maximumQuantity, int currentQuantity, int threshold) {
this.inventoryId = inventoryId;
this.maximumQuantity = maximumQuantity;
this.currentQuantity = currentQuantity;
this.threshold = threshold;
}
}
public class InventoryProblem {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Inventory[] arr = new Inventory[4];
// Reading 4 inventory objects
for (int i = 0; i < arr.length; i++) {
String inventoryId = sc.nextLine();
int maxQty = sc.nextInt();
int currQty = sc.nextInt();
int threshold = sc.nextInt();
sc.nextLine(); // Consume the leftover newline
arr[i] = new Inventory(inventoryId, maxQty, currQty, threshold);
}
int limit = sc.nextInt();
Inventory[] res = Replenish(arr, limit);
// Print result with status
for (int i = 0; i < res.length; i++) {
Inventory inv = res[i];
int threshold = inv.threshold;
String status;
if (threshold > 75) {
status = "Critical Filling";
} else if (threshold >= 50) {
status = "Moderate Filling";
} else {
status = "Non-Critical Filling";
}
System.out.println(inv.inventoryId + " " + status);
}
}
public static Inventory[] Replenish(Inventory[] arr, int limit) {
ArrayList<Inventory> list = new ArrayList<>();
for (int i = 0; i < arr.length; i++) {
if (limit >= arr[i].threshold) {
list.add(arr[i]);
}
}
return list.toArray(new Inventory[0]);
}
}