Skip to content

Commit a329a58

Browse files
committed
Inventory (IPA-35)
1 parent e45b460 commit a329a58

2 files changed

Lines changed: 126 additions & 32 deletions

File tree

IPA24.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import java.util.*;
2+
public class IPA24
3+
{
4+
public static void main(String[] args) {
5+
Scanner sc= new Scanner(System.in);
6+
Inventory[] in = new Inventory[4];
7+
for (int i = 0; i < in.length; i++) {
8+
String a = sc.nextLine();
9+
int b = sc.nextInt();sc.nextLine();
10+
int c = sc.nextInt();sc.nextLine();
11+
int d = sc.nextInt();sc.nextLine();
12+
13+
in[i] = new Inventory(a, b, c, d);
14+
}
15+
int lim = sc.nextInt();sc.nextLine();
16+
Inventory[] ans = Replenish(in,lim);
17+
if(ans!=null)
18+
{
19+
for (int i = 0; i < ans.length; i++) {
20+
if(ans[i].getTh()>75)
21+
{
22+
System.out.println(ans[i].getId()+" Critical Falling");
23+
}
24+
else if(ans[i].getTh()>=50 && ans[i].getTh()<=75)
25+
{
26+
System.out.println(ans[i].getId()+" Moderate Filling");
27+
}
28+
else
29+
{
30+
System.out.println(ans[i].getId()+" Non-Critical Filling");
31+
}
32+
}
33+
}
34+
}
35+
public static Inventory[] Replenish(Inventory[] in, int lim)
36+
{
37+
Inventory[] arr = new Inventory[0];
38+
for (int i = 0; i < in.length; i++) {
39+
if(lim>=in[i].getTh())
40+
{
41+
arr = Arrays.copyOf(arr,arr.length+1);
42+
arr[arr.length-1] = in[i];
43+
}
44+
}
45+
if(arr.length>0)
46+
{
47+
return arr;
48+
}
49+
else
50+
{
51+
return null;
52+
}
53+
}
54+
}
55+
56+
class Inventory
57+
{
58+
private String id;
59+
private int max, cur, th;
60+
public Inventory(String id, int max, int cur, int th) {
61+
this.id = id;
62+
this.max = max;
63+
this.cur = cur;
64+
this.th = th;
65+
}
66+
public String getId() {
67+
return id;
68+
}
69+
public void setId(String id) {
70+
this.id = id;
71+
}
72+
public int getMax() {
73+
return max;
74+
}
75+
public void setMax(int max) {
76+
this.max = max;
77+
}
78+
public int getCur() {
79+
return cur;
80+
}
81+
public void setCur(int cur) {
82+
this.cur = cur;
83+
}
84+
public int getTh() {
85+
return th;
86+
}
87+
public void setTh(int th) {
88+
this.th = th;
89+
}
90+
91+
92+
}

IPA24.txt

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
1-
## Problem Statement
2-
31
Create class Inventory with below attributes:
2+
43
inventoryId - String
54
maximumQuantity - int
65
currentQuantity - int
76
threshold - int
87

9-
Create class Solution and implement static method "replenish" in the Solution class.
8+
Create class Solution and implement static method "Replenish" in the Solution class.
109
This method will take array of Inventory objects and a limit int as parameters.
11-
And will return another array of Inventory objects where the limit int is lesser than or equal to the original array of Inventory object's threshold attribute.
10+
And will return another array of Inventory objects where the limit int is greater than or equal to the original array of
11+
Inventory object's threshold attribute.
1212

1313
Write necessary getters and setters.
1414

15-
Before calling "replenish" method in the main method, read values for four Inventory objects referring the attributes in above sequence along with a int limit.
16-
Then call the "replenish" method and write logic in main method to print "Critical Filling",if the threshold attribute is greater than 75. Else if the threshold attribute is between 50 and 75 then print "Moderate Filling". Else print "Non-Critical Filling"
17-
18-
## Input
19-
20-
1
21-
100
22-
50
23-
50
24-
2
25-
200
26-
60
27-
40
28-
3
29-
150
30-
35
31-
45
32-
4
33-
80
34-
45
35-
40
36-
45
37-
38-
## Output
39-
40-
2 Non-Critical Filling
41-
3 Non-Critical Filling
42-
4 Non-Critical Filling
15+
Before calling "Replenish" method in the main method, read values for four Inventory objects referring the attributes in above
16+
sequence along with a int limit.Then call the "Replenish" method and write logic in main method to print "Critical Filling",
17+
if the threshold attribute is greater than 75. Else if the threshold attribute is between 50 and 75 then print
18+
"Moderate Filling". Else print "Non-Critical Filling"
19+
20+
Input
21+
---------------------------
22+
1
23+
100
24+
50
25+
50
26+
2
27+
200
28+
60
29+
40
30+
3
31+
150
32+
35
33+
45
34+
4
35+
80
36+
45
37+
40
38+
45
39+
40+
Output
41+
----------------------------
42+
2 Non-Critical Filling
43+
3 Non-Critical Filling
44+
4 Non-Critical Filling

0 commit comments

Comments
 (0)