-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution_ap_1
508 lines (498 loc) · 21.8 KB
/
solution_ap_1
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
package ap_assignment;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
class AddV{
private String name;
private int dose;
private int gap;
AddV(String name,int dose,int gap){
this.name = name;
this.dose = dose;
this.gap = gap;
}
AddV(String name,int dose){
this.name = name;
this.dose = dose;
}
public String getName(){
return this.name;
}
public int getDose(){
return this.dose;
}
public int getGap(){
return this.gap;
}
}
class reghos{
private String name;
private int pin;
private String hospiatalid;
reghos(String name,int pin,String hospiatalid){
this.name = name;
this.pin = pin;
this.hospiatalid = hospiatalid;
}
public String getHospiatalid(){
return this.hospiatalid;
}
// static HashMap<String ,Integer> map_name_ID= new HashMap<>();
// public void idgen(){
// if(!map_name_ID.containsKey(name) ){
// map_name_ID.put(name,100000+map_name_ID.size());
// }
// }
public String getName(){
return this.name;
}
public int getPin(){
return this.pin;
}
}
class Regcitizen{
private String name;
private int age;
private String uniqueID;
private String currentstatus;
private int no_doses;
private int duedateford;
private String vaccinef;
private int rem;
Regcitizen(String name,int age,String uniqueID){
this.name = name;
this.age = age;
this.uniqueID = uniqueID;
this.currentstatus = "Citizen REGISTERED";
this.duedateford = 1;
}
public void udstatus(int d,String vf,int total){
this.no_doses++;
this.duedateford+=d;
this.vaccinef = vf;
this.rem = total-this.no_doses;
if(this.rem!=0){
this.currentstatus = "PARTIALLY VACCINATED";
}else if(this.rem==0){
this.currentstatus = "FULLY VACCINATED";
}
// if(this.currentstatus.equals("REGISTERED")){
// this.currentstatus = "PARTIALLY VACCINATED";
// }else if(this.currentstatus.equals("PARTIALLY VACCINATED")){
// this.currentstatus = "FULLY VACCINATED";
// }
}
public String getName(){
return this.name;
}
public int getAge(){
return this.age;
}
public String getUniqueID(){
return this.uniqueID;
}
public String getCurrentstatus(){
return this.currentstatus;
}
public int getNo_doses(){
return this.no_doses;
}
public int getDuedateford(){
return this.duedateford;
}
public String getVaccinef(){
return this.vaccinef;
}
}
class addslot{
private String hosID;
private int slots;
private int daynumber;
private int EnterQuatity;
private String cvorcd;
addslot(String hosID,int slots,int daynumber,int EnterQuatity,String cvorcd){
this.hosID = hosID;
this.slots = slots;
this.daynumber = daynumber;
this.EnterQuatity = EnterQuatity;
this.cvorcd = cvorcd;
}
void decremental(){
this.EnterQuatity--;
}
public String getHosID(){
return this.hosID;
}
public int getSlots(){
return this.slots;
}
public int getDaynumber(){
return this.daynumber;
}
public int getEnterQuatity(){
return this.EnterQuatity;
}
public String getCvorcd(){
return this.cvorcd;
}
}
//class bookslot extends reghos{
//
// bookslot(String name, int pin) {
// super(name, pin);
// }
//}
public class Ap_Assignment1 {
// static class Reader {
// static BufferedReader reader;
// static StringTokenizer tokenizer;
//
// static void init(InputStream input) {
// reader = new BufferedReader(new InputStreamReader(input));
// tokenizer = new StringTokenizer("");
// }
//
// static String next() throws IOException {
// while (!tokenizer.hasMoreTokens()) {
// //TODO add check for eof if necessary
// tokenizer = new StringTokenizer(
// reader.readLine());
// }
// return tokenizer.nextToken();
// }
//
// static int nextint() throws IOException {
// return Integer.parseInt(next());
// }
//
// static long nextlong() throws IOException {
// return Long.parseLong(next());
// }
//
// static double nextdouble() throws IOException {
// return Double.parseDouble(next());
// }
//
// }
public static void main(String[] args) throws IOException {
int UNID = 100000;
//Reader.init(System.in);
Scanner sc = new Scanner(System.in);
System.out.println("CoWin Portal initialized....");
System.out.println();
System.out.println("Enter no. of queries you want to perform:");
int t = sc.nextInt();
HashMap<Integer, reghos> map_pin_name = new HashMap<>();
//ArrayList<reghos> addvaccine_hos = new ArrayList<>();
ArrayList<AddV> addv = new ArrayList<>();
ArrayList<reghos> ahos = new ArrayList<>();
ArrayList<addslot> asslot = new ArrayList<>();
ArrayList<Regcitizen> aregcity = new ArrayList<>();
while (t-- > 0) {
System.out.println("-".repeat(30));
System.out.println();
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"
);
System.out.println();
System.out.println("-".repeat(30));
int n = sc.nextInt();
if (n == 1) {
System.out.println("Enter vaccine name:");
String name = sc.next();
System.out.println("Enter no. of doses:");
int dose = sc.nextInt();
if(dose==1){
AddV a = new AddV(name, dose, 0);
addv.add(a);
System.out.println("Vaccine Name: " + a.getName() + ", " + "Number of Doses: " + a.getDose() + ", " + "Gap Between Doses:" + a.getGap());
}else {
System.out.println("Enter gap between Doses:");
int gap = sc.nextInt();
AddV a = new AddV(name, dose, gap);
addv.add(a);
System.out.println("Vaccine Name: " + a.getName() + ", " + "Number of Doses: " + a.getDose() + ", " + "Gap Between Doses:" + a.getGap());
}
// if (dose == 2) {//dose doubt!
// System.out.println("Enter gap between Doses:");
// int gap = Reader.nextint();
// AddV a = new AddV(name, dose, gap);
// addv.add(a);
// System.out.println("Vaccine Name: " + a.getName() + ", " + "Number of Doses: " + a.getDose() + ", " + "Gap Between Doses:" + a.getGap());
// } else if (dose == 1) {
// AddV a = new AddV(name, dose);
// addv.add(a);
// System.out.println("Vaccine Name: " + a.getName() + ", " + "Number of Doses: " + a.getDose() + ", " + "Gap Between Doses:" + 0);
// } else {
// System.out.println("Please Enter valid no. of doses!");
// }
} else if (n == 2) {
UNID++;
System.out.println("Enter Hospital Name:");
String str = sc.next();
System.out.println("Enter your PinCode:");
String p = sc.next();
if (p.length() != 6) {
System.out.println("Invalid PinCode!");
}
if (p.length() > 6) {
while (true) {
String pp = sc.nextLine();
if (pp.length() == 6) {
p = pp;
break;
}
System.out.println("Please Enter valid PinCode!");
}
}
reghos rh = new reghos(str, Integer.parseInt(p),String.valueOf(UNID));
map_pin_name.put(UNID, rh);
ahos.add(rh);
//System.out.println(ahos.size()+"*");
System.out.print("Hospital Name: " + rh.getName() + ",PinCode: " + rh.getPin());
System.out.println(",Unique ID: " + UNID);
} else if (n == 3) {
System.out.println("Please Enter your name:");
String str = sc.next();
System.out.println("Please Enter your age:");
int age = sc.nextInt();
System.out.println("Please Enter your Unique ID:");
String uid = sc.next();
if (uid.length() != 12) {
System.out.println("Invalid UniqueId!");
}
boolean flag = false;
for(int i = 0;i<aregcity.size();i++){
if(aregcity.get(i).getUniqueID().equals(uid)){
flag = true;
}
}
if(!flag && age>=18){
Regcitizen rc = new Regcitizen(str, age, uid);
System.out.println("Citizen Name: " + rc.getName() + ", Age: " + rc.getAge() + ", Unique ID: " + rc.getUniqueID());
aregcity.add(rc);
}
if (age < 18) {
System.out.println("Only above 18 are allowed");
}
// else {
// aregcity.add(rc);
// }
} else if (n == 4) {
System.out.println("Enter Hospital ID:");
String str = sc.next();
System.out.println("Enter number of Slots to be added:");
int day = sc.nextInt();
int daystore = day;
while (day-- > 0) {
System.out.println("Enter Day Number:");
int no_day = sc.nextInt();
System.out.println("Enter Quantity:");
int no_quantity = sc.nextInt();
System.out.println("Select Vaccine:");
int pc = 0;
for (int i = 0; i < addv.size(); i++) {
System.out.println(i + "." + addv.get(i).getName());
//pc++;
//arrstr.add("Slot added by Hospital " + slot.hosID + " for Day: " + no_day + ", Available Quantity: " + no_quantity + " of Vaccine"+a.getName());
}
int idx = sc.nextInt();
addslot slot = new addslot(str, daystore, no_day, no_quantity, addv.get(idx).getName());
//System.out.println(slot.getHosID()+"**");
asslot.add(slot);
//System.out.println(asslot.size()+"*");
System.out.println("Slot added by Hospital " + str + " for Day: " + no_day + ", Available Quantity: " + no_quantity + " of Vaccine " + addv.get(idx).getName());
//doubt!
}
} else if (n == 5) {
System.out.println("Enter your Unique ID:");
String str = sc.next();
System.out.println("""
1. Search by area
2. Search by Vaccine
3. Exit""");
System.out.println("Enter option");
int num = sc.nextInt();
if (num == 1) {
System.out.println("Enter PinCode");
int pin = sc.nextInt();
Iterator it = map_pin_name.entrySet().iterator();
while (it.hasNext()) {
Map.Entry map = (Map.Entry) it.next();
reghos h = ((reghos) map.getValue());
if (h.getPin() == pin) {
System.out.println(map.getKey() + " " + h.getName());
}
}
System.out.println("Enter hospital ID:");
String choosenId = sc.next();
//Iterator itaslot = asslot.iterator();int pc = 0;
for (int i = 0; i < asslot.size();i++) {
if (asslot.get(i).getHosID().equals(choosenId)) {
System.out.print(i + "-> Day:" + asslot.get(i).getDaynumber() + " Available Qty:" + asslot.get(i).getEnterQuatity() + " Vaccine:" + asslot.get(i).getCvorcd() + "\n");
}
}
// while (itaslot.hasNext()){
// addslot a = ((addslot)itaslot.next());
// if(a.hosID.equals(choosenId)){
// System.out.print(pc+"-> Day:"+a.daynumber+" Available Qty:"+a.EnterQuatity+" Vaccine:"+a.cvorcd+"\n");
// }
// pc++;
// }
System.out.println("Choose slot:");
int tochoose = sc.nextInt();
int y = 0;
for (int i = 0; i < aregcity.size(); i++) {
if (str.equals(aregcity.get(i).getUniqueID()) && !aregcity.get(i).getCurrentstatus().equals("FULLY VACCINATED") && aregcity.get(i).getDuedateford()<=asslot.get(tochoose).getDaynumber()) {
y = 1;
System.out.println(aregcity.get(i).getName() + " Vaccinated with " + asslot.get(tochoose).getCvorcd());//bacha hai yeh!!!
int x = 0;
int z = 0;
//int z = asslot.get(i).getEnterQuatity();
for(int j = 0;j<addv.size();j++){
if(addv.get(j).getName().equals(asslot.get(tochoose).getCvorcd())){
x = addv.get(j).getGap();
z = addv.get(j).getDose();
}
}//todo
//System.out.println(x);
asslot.get(tochoose).decremental();
aregcity.get(i).udstatus(x,asslot.get(tochoose).getCvorcd(),z);
}
}
if(y==0){
System.out.println("No slot available! {before due date}");
}
// if(bookslot.map_pin_name.containsKey(pin)){
// System.out.println(bookslot.map_name_ID.get(bookslot.map_pin_name.get(pin))+" "+bookslot.map_pin_name.get(pin));
// }
} else if (num == 2) {
System.out.println("Enter Vaccine name:");
String choosenvaccine = sc.next();
for(int i = 0;i<asslot.size();i++){
if(asslot.get(i).getCvorcd().equals(choosenvaccine)){
for (int j = 0;j<ahos.size();j++){
if(ahos.get(j).getHospiatalid().equals(asslot.get(i).getHosID())){
System.out.println(asslot.get(i).getHosID()+" "+ahos.get(j).getName());
}
}
}
}
System.out.println("Enter hospital ID:");
String choosenId = sc.next();
//Iterator itaslot = asslot.iterator();int pc = 0;
for (int i = 0; i < asslot.size(); i++) {
if (asslot.get(i).getHosID().equals(choosenId) && asslot.get(i).getCvorcd().equals(choosenvaccine)) {
System.out.print(i + "-> Day:" + asslot.get(i).getDaynumber() + " Available Qty:" + asslot.get(i).getEnterQuatity() + " Vaccine:" + asslot.get(i).getCvorcd() + "\n");
}
}
// while (itaslot.hasNext()){
// addslot a = ((addslot)itaslot.next());
// if(a.getHosID().equals(choosenId)){
// System.out.print(pc+"-> Day:"+a.getDaynumber()+" Available Qty:"+a.getEnterQuatity()+" Vaccine:"+a.getCvorcd()+"\n");
// }
// pc++;
// }
System.out.println("Choose slot:");
int tochoose = sc.nextInt();
int y = 0;
for (int i = 0; i < aregcity.size(); i++) {
if (str.equals(aregcity.get(i).getUniqueID()) && !aregcity.get(i).getCurrentstatus().equals("FULLY VACCINATED") && aregcity.get(i).getDuedateford()<=asslot.get(tochoose).getDaynumber()) {
if(aregcity.get(i).getVaccinef()!=null && aregcity.get(i).getVaccinef().equals(asslot.get(tochoose).getCvorcd())){
y = 1;
System.out.println(aregcity.get(i).getName() + " Vaccinated with " + asslot.get(tochoose).getCvorcd());//bacha hai yeh!!!
int x = 0;
int z = 0;
for(int ii = 0;ii<addv.size();ii++){
if(addv.get(ii).getName().equals(asslot.get(tochoose).getCvorcd())){
x = addv.get(ii).getGap();
z = addv.get(ii).getDose();
}
}//todo
asslot.get(tochoose).decremental();
aregcity.get(i).udstatus(x,asslot.get(tochoose).getCvorcd(),z);
}
if(aregcity.get(i).getVaccinef()==null) {
y = 1;
System.out.println(aregcity.get(i).getName() + " Vaccinated with " + asslot.get(tochoose).getCvorcd());//bacha hai yeh!!!
int x = 0;
int z = 0;
for (int ii = 0; ii < addv.size(); ii++) {
if (addv.get(ii).getName().equals(asslot.get(tochoose).getCvorcd())) {
x = addv.get(ii).getGap();
z = addv.get(ii).getDose();
}
}
//todo
asslot.get(tochoose).decremental();
aregcity.get(i).udstatus(x, asslot.get(tochoose).getCvorcd(), z);
}
}
}
if(y==0){
System.out.println("No slot available! {before due date!}");
}
// if(bookslot.map_pin_name.containsKey(pin)){
// System.out.println(bookslot.map_name_ID.get(bookslot.map_pin_name.get(pin))+" "+bookslot.map_pin_name.get(pin));
// }
// for(int i = 0;i<addv.size();i++){
// if(addv.get(i).getName().equals(asslot.get(tochoose).getCvorcd())){
// x = addv.get(i).getGap();
// }
// }//todo
// asslot.get(tochoose).decremental();
// aregcity.get(y).udstatus(x,asslot.get(tochoose).getCvorcd());
//
}
else if(num==3){
System.out.println("try again!");
}
}
else if (n == 6) {
System.out.println("Enter Hospital id:");
String str = sc.next();
for (int i = 0; i < asslot.size(); i++) {
if (asslot.get(i).getHosID().equals(str)) {
// int x = asslot.get(i).slots;
// for(int j = 1;j<=x;j++){
System.out.println("Day: " + asslot.get(i).getDaynumber() + " Vaccine: " + asslot.get(i).getCvorcd() + " Available Qty: " + asslot.get(i).getEnterQuatity());
// }
}
}
} else if (n == 7) {
System.out.println("Enter patient ID:");
String str = sc.next();
for(int i = 0;i<aregcity.size();i++){
if(aregcity.get(i).getUniqueID().equals(str)){
System.out.println(aregcity.get(i).getCurrentstatus());
if(!aregcity.get(i).getCurrentstatus().equals("Citizen REGISTERED")){
System.out.println(aregcity.get(i).getVaccinef());
System.out.println(aregcity.get(i).getNo_doses());
if(!aregcity.get(i).getCurrentstatus().equals("FULLY VACCINATED")){
System.out.println(aregcity.get(i).getDuedateford());
}
}
}
}
} else if (n == 8) {
break;
}
System.out.println();
System.out.println("-".repeat(30));
System.out.println();
System.out.println("{Menu Options}");
}
}
}
//array regcit
//array of vaccine
//