-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppClass.java
More file actions
212 lines (190 loc) · 7.38 KB
/
Copy pathAppClass.java
File metadata and controls
212 lines (190 loc) · 7.38 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Scanner;
public class AppClass {
Scanner sc = new Scanner(System.in);
private ArrayList<Patient> camp;
private ArrayList<Institute> institute;
private ArrayList<Patient> remove_Patients;
private ArrayList<Institute> remove_Institute;
private int non_Admitted_Patients;
private int current_Open_Institute;
private int id = 1;
AppClass(int tot) {
this.camp = new ArrayList<>();
reg_Patients(tot);
this.institute = new ArrayList<>();
this.current_Open_Institute = 0;
this.non_Admitted_Patients = tot;
this.remove_Institute = new ArrayList<>();
this.remove_Patients = new ArrayList<>();
run();
}
void reg_Patients(int tot) {
for (int i = 0; i < tot; i++) {
String name = sc.next();
float temp = sc.nextFloat();
int oxygen_Lev = sc.nextInt();
int age = sc.nextInt();
Patient new_patient = new Patient(name, age, oxygen_Lev, temp);
new_patient.setUnique_ID(id++);
camp.add(new_patient);
}
}
void admitPatient(Institute in) {
for (Patient p : camp) {
if (in.getAvailable_bed() > 0) {
if (p.getAdmit_Status() == 0 && p.getOxygen_Level() >= in.getMin_Oxygen()) {
p.setAdmit_Status(1);
p.setMy_Institute(in);
in.setAvailable_bed();
in.setMy_Patients(p);
non_Admitted_Patients--;
}
} else {
break;
}
}
for (Patient p : camp) {
if (in.getAvailable_bed() > 0) {
if (p.getAdmit_Status() == 0 && p.getBody_Temp() <= in.getMax_Temp()) {
p.setAdmit_Status(1);
p.setMy_Institute(in);
in.setAvailable_bed();
in.setMy_Patients(p);
non_Admitted_Patients--;
}
} else {
break;
}
}
}
void remove_Account_Admitted() {
System.out.println("IDS of those patients whose accounts are now removed");
for (Patient p : camp) {
if (p.getAdmit_Status() == 1 && (!remove_Patients.contains(p))) {
remove_Patients.add(p);
System.out.println(p.getUnique_ID());
}
}
}
void remove_Institute() {
for (Institute in : institute) {
System.out.println("Names of CLOSED Health Care Institute whose accounts are now removed");
if (in.getStatus().equals("CLOSED") && !remove_Institute.contains(in)) {
remove_Institute.add(in);
System.out.println(in.getName());
}
}
}
void print_Non_Admitted_Patients() {
System.out.println("Number of patients still in camp- "+non_Admitted_Patients);
}
void print_Current_Open_Institute() {
System.out.println("Number of currently admitting healthcare Institutes- "+current_Open_Institute);
}
void print_Institute_Details(Institute in){
System.out.println("Name:-"+in.getName());
System.out.println("Temperature should be <="+in.getMax_Temp());
System.out.println("Oxygen-Levels>="+in.getMin_Oxygen());
System.out.println("Number of Available beds="+in.getAvailable_bed());
System.out.println("Admission Status-"+in.getStatus());
}
void run() {
while (non_Admitted_Patients!= 0) {
int query = sc.nextInt();
if (query == 1) {
String name = sc.next();
System.out.print("Temperature Criteria-");
float temp = sc.nextFloat();
System.out.println();
System.out.print("Oxygen-Levels-");
int o2level = sc.nextInt();
System.out.println();
System.out.print("Number of Available beds-");
int bedNum = sc.nextInt();
Institute in = new Institute(name, temp, o2level, bedNum);
institute.add(in);
print_Institute_Details(in);
admitPatient(in);
//for setting status of hospital
if (in.getAvailable_bed() == 0) {
in.setStatus("CLOSED");
}
else {
current_Open_Institute++;
}
//for output showing
in.set_RecoveryDays();
}
else if (query == 2) {
remove_Account_Admitted();
}
else if (query == 3) {
remove_Institute();
}
else if (query == 4) {
print_Non_Admitted_Patients();
}
else if (query == 5) {
print_Current_Open_Institute();
}
else if (query == 6) {
String in = sc.next();
int flag = 0;
for (Institute institute_obj : institute) {
if (!remove_Institute.contains(institute_obj) && institute_obj.getName().equals(in)) {
print_Institute_Details(institute_obj);
flag = 1;
break;
}
}
if(flag == 0){
System.out.println("Institute not found");
}
}
else if (query == 7) {
int id = sc.nextInt();
int flag = 0;
for(Patient p : camp){
if(p.getUnique_ID() == id && !remove_Patients.contains(p) ){
System.out.println("Name:-"+p.getName());
System.out.println("Temperature:-"+p.getBody_Temp());
System.out.println("Oxygen levels:-"+p.getOxygen_Level());
flag = 1;
if(p.getAdmit_Status()==1) {
System.out.println("Admission Status -Admitted");
System.out.println("Admitting Institute-"+p.getMy_Institute());
}
else
System.out.println("Admission Status -Not-Admitted");
break;
}
}
if(flag == 0){
System.out.println("ID not Found");
}
} else if (query == 8) {
for(Patient p:camp){
//System.out.println(p.getName());
if(!remove_Patients.contains(p)){
System.out.print(p.getName()+" ");
System.out.println(p.getUnique_ID());
}
}
} else {
String in_name = sc.next();
int flag = 0;
for(Institute institute_obj:institute){
if(!remove_Institute.contains(institute_obj) && institute_obj.getName().equals(in_name)){
flag = 1;
institute_obj.print_PatientsName();
}
}
if(flag == 0){
System.out.println("Institute not found");
}
}
}
}
}