-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMedicineProblem.java
More file actions
68 lines (55 loc) · 1.61 KB
/
MedicineProblem.java
File metadata and controls
68 lines (55 loc) · 1.61 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
import java.util.*;
class Medicine{
String MedicineName;
String batch ;
String disease;
int price;
public Medicine(String MedicineName , String batch, String disease , int price){
this.MedicineName = MedicineName;
this.batch = batch;
this.disease = disease ;
this.price = price;
}
public String getMedicineName(){
return MedicineName;
}
public String getBatch(){
return batch;
}
public String getDisease(){
return disease;
}
public int getPrice(){
return price;
}
}
public class MedicineProblem {
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
Medicine[]arr = new Medicine[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();
sc.nextLine();
arr[i] = new Medicine(a, b, c, d);
}
String disease = sc.nextLine();
Medicine[] res = getPriceByDisease(arr,disease);
for(int i =0; i<res.length; i++){
if(disease.equalsIgnoreCase(res[i].disease)){
System.out.println(res[i].price);
}
}
}
public static Medicine[] getPriceByDisease(Medicine[]arr ,String disease){
List<Medicine>list = new ArrayList<>();
for(int i =0; i<arr.length; i++){
if(disease.equalsIgnoreCase(arr[i].disease)){
list.add(arr[i]);
}
}
return list.toArray(new Medicine[0]);
}
}