-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatientRecords.java
More file actions
57 lines (43 loc) · 1.57 KB
/
Copy pathPatientRecords.java
File metadata and controls
57 lines (43 loc) · 1.57 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
import java.util.stream.Collectors;
import java.util.Arrays;
public class PatientRecords {
public static void main(String[] args) {
Patient p1 = new Patient("p1", 20, "Corona", 18000);
Patient p2 = new Patient("p2", 26, "Corona", 23000);
Patient p3 = new Patient("p3", 29, "Cold", 6000);
Patient p4 = new Patient("p4", 23, "Fue", 800);
Patient p5 = new Patient("p5", 14, "Corona", 12000);
java.util.List<Patient> patients = Arrays.asList(p1, p2, p3, p4, p5);
patients.stream().filter(p -> p.getDisease().equals("Corona") && p.getAge() < 25).forEach(System.out::println);
Double averageBillPaid = patients.stream().filter(p -> p.getDisease().equals("Corona")).collect(Collectors.averagingDouble(Patient::getAmount));
System.out.println("Average bill paid: $" + averageBillPaid);
}
}
class Patient {
private final String name;
private final int age;
private final String disease;
private final double amount;
public Patient(String name, int age, String disease, double amount) {
this.name = name;
this.age = age;
this.disease = disease;
this.amount = amount;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getDisease() {
return disease;
}
public double getAmount() {
return amount;
}
@Override
public String toString() {
return "Patient{name='" + name + "', age=" + age + ", disease='" + disease + "', amount=" + amount + '}';
}
}