-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment1.java
More file actions
534 lines (476 loc) · 21.5 KB
/
Assignment1.java
File metadata and controls
534 lines (476 loc) · 21.5 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
package com.company;
import java.util.*;
class Vaccine {
private String vaccine;
private int doses;
private int gap;
public Vaccine(){
this.vaccine=vaccine;
getVaccine();
}
public Vaccine(String vaccine,int doses,int gap){
this.vaccine=vaccine;
this.doses=doses;
this.gap=gap;
}
public void displayInfo(){
System.out.println("Vaccine name: "+this.vaccine+" ,Number of doses: "+this.doses+" ,Gap Between Doses: "+this.gap);
System.out.println("--------------------------------");
}
public int getGap() {
return gap;
}
public int getDoses() {
return doses;
}
public String getVaccine() {
return vaccine;
}
}
class RegHospital{
private String hospital_name;
private int pincode;
private int ID;
public static int x=0;
public RegHospital(String hospital_name,int pincode){
this.hospital_name=hospital_name;
this.pincode=pincode;
this.ID= 100000+x;
x+=1;
}
public int getID() {
return ID;
}
public int getPincode() {
return pincode;
}
public String getHospital_name() {
return hospital_name;
}
public void display(){
System.out.println("Hospital Name: "+this.hospital_name+" ,PinCode: "+this.pincode+" ,Unique ID "+this.ID);
System.out.println("-------------------------------------");
}
public void setSlot(int day_no,int quantity,String vaccine,int slot){
Slots s=new Slots(this.ID,day_no,quantity,vaccine,slot);
s.display();
}
}
class Citizen {
private String name;
private int age;
private long ID;
private String status;
private int due_date;
private int doses;
private Vaccine v;
private String vax_given;
public Citizen(String name, int age, long ID) {
this.name = name;
this.age = age;
this.ID = ID;
this.status = "REGISTERED";
}
public void setStatus(String status) {
this.status = status;
}
String getName() {
return name;
}
public int getDue_date() {
return due_date;
}
public void setDue_date(int due_date) {
this.due_date = due_date;
}
public String getStatus() {
return status;
}
public long getID() {
return ID;
}
public void display() {
System.out.println("Citizen Name: " + this.name + " ,Age: " + this.age + " ,Unique ID :" + this.ID);
if (this.age < 18)
System.out.println(" \nOnly above 18 are allowed");
System.out.println("\n--------------------------------- \n");
}
public void given_vaccine(Vaccine v,String vax_given) {
doses++;
this.v = v;
this.vax_given=vax_given;
}
public String getVax_given() {
return vax_given;
}
public void Status() {
if (doses == 0) {
System.out.println("Citizen REGISTERED");
} else if (doses == v.getDoses()) {
System.out.println("FULLY VACCINATED");
System.out.println("Vaccine Given:" + v.getVaccine());
System.out.println("Number of Doses given:" + doses);
} else if (doses < v.getDoses()) {
System.out.println("PARTIALLY VACCINATED");
System.out.println("Vaccine Given:" + v.getVaccine());
System.out.println("Number of Doses given:" + doses);
System.out.println("Next Dose due date:" + this.due_date);
}
}
}
class Slots {
private int id;
private int day_no;
private int q;
private String vaccine;
private int slot;
Slots(int id, int day_no, int q, String vaccine, int slot) {
this.id = id;
this.day_no = day_no;
this.q = q;
this.vaccine = vaccine;
this.slot = slot;
Main.slots.add(this);
}
public int getId() {
return id;
}
public int getDay_no() {
return day_no;
}
public int getQ() {
return q;
}
public void setQ(int q) {
this.q = q;
}
public String getVaccine() {
return vaccine;
}
public int getSlot() {
return slot;
}
void display() {
System.out.println("Slot added by Hospital " + this.id + " for Day: " + this.day_no + " ,Available Quantity: " + this.q + " of Vaccine " + this.vaccine);
}
Slots(RegHospital h) {
this.id = h.getID();
}
}
public class Main {
public static ArrayList<Vaccine> vaccines = new ArrayList<Vaccine>();
public static ArrayList<RegHospital> hospitals = new ArrayList<RegHospital>();
public static ArrayList<Citizen> citizens = new ArrayList<Citizen>();
public static ArrayList<Slots> slots = new ArrayList<Slots>();
static boolean checkID(long ID){
for(int i=0;i<citizens.size();i++){
Citizen c=citizens.get(i);
if(ID == c.getID())
return false;
}
return true;
}
static boolean checkvax(String vax){
for(int i=0;i<vaccines.size();i++){
Vaccine v=vaccines.get(i);
if(vax.equals(v.getVaccine()))
return false;
}
return true;
}
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
System.out.println("CoWin Portal initialized.... ");
System.out.println("---------------------------------");
while (true) {
System.out.println("1. Add Vaccine \n" + "2. Register Hospital \n" + "3. Register Citizen \n" + "4. Add Slot for Vaccination \n" + "5. Book Slot for Vaccination \n" + "6. List all slots for a hospital \n" + "7. Check Vaccination Status \n" + "8. Exit\n");
int n = scn.nextInt();
if (n == 8)
break;
if (n == 1) {
System.out.print("Vaccine Name: ");
String vaccine = scn.next();
Boolean flag=checkvax(vaccine);
if(flag){
System.out.print("Number of doses: ");
int doses = scn.nextInt();
int gap;
if(doses==1)
gap=0;
else {
System.out.print("Gap between Doses: ");
gap = scn.nextInt();
}
Vaccine vax = new Vaccine(vaccine, doses, gap);
vaccines.add(vax);
vax.displayInfo();
}
else {
System.out.println("Vaccine was already registered");
continue;
}
}
if (n == 2) {
System.out.print("Hospital Name: ");
String hospital_name = scn.next();
System.out.print("PinCode: ");
int pincode = scn.nextInt();
RegHospital hospital = new RegHospital(hospital_name, pincode);
hospitals.add(hospital);
hospital.display();
}
if (n == 3) {
System.out.print("Citizen Name : ");
String name = scn.next();
System.out.print("Age: ");
int age = scn.nextInt();
System.out.print("Unique ID: ");
long ID = scn.nextLong();
boolean check = checkID(ID);
if(check) {
Citizen cit = new Citizen(name, age, ID);
citizens.add(cit);
cit.display();
}
else
{
System.out.println("Citizen was already registered");
}
}
if (n == 4) {
System.out.print("Enter Hospital ID: ");
int ID = scn.nextInt();
System.out.print("Enter number of Slots to be added: ");
int slot_no = scn.nextInt();
int a = 1;
while (a++ <= slot_no) {
System.out.print("Enter Day Number: ");
int day_no = scn.nextInt();
System.out.print("Enter Quantity: ");
int q = scn.nextInt();
System.out.println("Select vaccine: ");
for (int i = 0; i < vaccines.size(); i++) {
Vaccine vax = vaccines.get(i);
System.out.println(i + ". " + vax.getVaccine());
}
int choice = scn.nextInt();
Vaccine vax = vaccines.get(choice);
String v = vax.getVaccine();
for (int i = 0; i < hospitals.size(); i++) {
RegHospital h = hospitals.get(i);
if (h.getID() == ID)
h.setSlot(day_no, q, v, a);
}
}
System.out.println("-----------------------");
}
if (n == 5) {
System.out.print("Enter patient Unique ID: ");
long ID = scn.nextLong();
String name_;
System.out.println("1. Search by area \n" + "2. Search by Vaccine \n" + "3. Exit");
System.out.println("Enter option: ");
int choice = scn.nextInt();
if (choice == 3)
continue;
else if (choice == 1) {
System.out.print("Enter PinCode: ");
int code = scn.nextInt();
for (int i = 0; i < hospitals.size(); i++) {
RegHospital h = hospitals.get(i);
if (h.getPincode() == code) {
System.out.println(h.getID() + ". " + h.getHospital_name());
}
}
System.out.print("Enter hospital ID: ");
int id = scn.nextInt();
ArrayList<Slots> potential_slots = new ArrayList<Slots>();
int l = 0;
for (int j = 0; j < slots.size(); j++) {
boolean flag = true;
boolean flag2=true;
boolean flag3=true;
Slots s = slots.get(j);
if (s.getId() == id) {
for (int i = 0; i < citizens.size(); i++) {
Citizen c = citizens.get(i);
if (c.getID() == ID) {
String status = c.getStatus();
if (status.equals("PARTIALLY VACCINATED") ) {
if (c.getDue_date() > s.getDay_no()) {
flag = false;
}
if(c.getStatus().equals("PARTIALLY VACCINATED") && !c.getVax_given().equals(s.getVaccine())){
flag =false;
}
if(s.getQ()==0)
flag = false;
}
if (status.equals("FULLY VACCINATED")){
System.out.println("Citizen is fully vaccinated");
flag =false;
flag2=false;
flag3=false;
break;
}
}
if(!flag2)
break;
}
if (flag == true) {
System.out.println(l + "-> " + "Day: " + s.getDay_no() + " Available quantity " + s.getQ() + " Vaccine " + s.getVaccine());
potential_slots.add(s);
l++;
}
}
if(!flag3)
break;
}
if (potential_slots.size() == 0) {
System.out.println("No slots available");
} else {
System.out.println("Choose slot :");
int res = scn.nextInt();
Slots s_ = potential_slots.get(res);
s_.setQ(s_.getQ() - 1);
for (int i = 0; i < citizens.size(); i++) {
Citizen c = citizens.get(i);
if (c.getID() == ID) {
name_ = c.getName();
System.out.println(name_ + " vaccinated with " + s_.getVaccine());
for (int k = 0; k < vaccines.size(); k++) {
Vaccine v = vaccines.get(k);
if (v.getVaccine() == s_.getVaccine()) {
c.setDue_date(s_.getDay_no() + v.getGap());
c.given_vaccine(v,s_.getVaccine());
}
}
}
}
for (int j = 0; j < citizens.size(); j++) {
Citizen c = citizens.get(j);
if (c.getID() == ID) {
if (c.getStatus() .equals( "REGISTERED")) {
c.setStatus("PARTIALLY VACCINATED");
} else if (c.getStatus().equals( "PARTIALLY VACCINATED"))
c.setStatus("FULLY VACCINATED");
}
}
}
} else if (choice == 2) {
System.out.print("Enter Vaccine name: ");
String vax = scn.next();
for (int i = 0; i < slots.size(); i++) {
Slots s = slots.get(i);
if (s.getVaccine().equals(vax)) {
int id = s.getId();
for (int j = 0; j < hospitals.size(); j++) {
RegHospital h = hospitals.get(j);
if (id == h.getID()) {
System.out.println(id + " " + h.getHospital_name());
}
}
}
}
System.out.print("Enter hospital ID: ");
int id = scn.nextInt();
ArrayList<Slots> potential_slots = new ArrayList<Slots>();
int l = 0;
for (int j = 0; j < slots.size(); j++) {
boolean flag = true;
boolean flag2 = true;
boolean flag3 = true;
Slots s = slots.get(j);
if (s.getId() == id) {
for (int i = 0; i < citizens.size(); i++) {
Citizen c = citizens.get(i);
if (c.getID() == ID) {
String status = c.getStatus();
if (status.equals("PARTIALLY VACCINATED")) {
if (c.getDue_date() > s.getDay_no()) {
flag = false;
}
if (c.getStatus().equals("PARTIALLY VACCINATED") && !c.getVax_given().equals(s.getVaccine())) {
flag = false;
}
if(s.getQ()==0)
flag = false;
}
if (status.equals("FULLY VACCINATED")) {
System.out.println("Citizen is fully vaccinated");
flag = false;
flag2 = false;
flag3 = false;
break;
}
}
if (!flag2)
break;
}
if (flag == true && s.getVaccine().equals(vax)) {
System.out.println(l + "-> " + "Day: " + s.getDay_no() + " Available quantity " + s.getQ() + " Vaccine " + s.getVaccine());
potential_slots.add(s);
l++;
}
}
if (!flag3)
break;
}
if (potential_slots.size() == 0) {
System.out.println("No slots available");
} else {
System.out.print("Choose slot :");
int res = scn.nextInt();
Slots s_ = potential_slots.get(res);
s_.setQ(s_.getQ() - 1);
for (int i = 0; i < citizens.size(); i++) {
Citizen c = citizens.get(i);
if (c.getID() == ID) {
name_ = c.getName();
System.out.println(name_ + " vaccinated with " + s_.getVaccine());
for (int k = 0; k < vaccines.size(); k++) {
Vaccine v = vaccines.get(k);
if (v.getVaccine() == s_.getVaccine()) {
c.setDue_date(s_.getDay_no() + v.getGap());
c.given_vaccine(v, s_.getVaccine());
}
}
}
}
for (int j = 0; j < citizens.size(); j++) {
Citizen c = citizens.get(j);
if (c.getID() == ID) {
if (c.getStatus().equals("REGISTERED")) {
c.setStatus("PARTIALLY VACCINATED");
} else if (c.getStatus().equals("PARTIALLY VACCINATED"))
c.setStatus("FULLY VACCINATED");
}
}
}
}
System.out.println("----------------------------");
}
if (n == 6) {
System.out.print("Enter Hospital Id: ");
int id = scn.nextInt();
for (int i = 0; i < slots.size(); i++) {
Slots s = slots.get(i);
if (s.getId() == id) {
System.out.println("Day: " + s.getDay_no() + " Vaccine: " + s.getVaccine() + " Available Qty: " + s.getQ());
}
}
System.out.println("----------------------------");
}
if (n == 7) {
System.out.print("Enter Patient ID: ");
long id = scn.nextLong();
for (int i = 0; i < citizens.size(); i++) {
Citizen c = citizens.get(i);
if (id == c.getID())
c.Status();
}
System.out.println("------------------------------");
}
}
}
}