-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSurveyTest.java
645 lines (507 loc) · 18.9 KB
/
SurveyTest.java
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
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
import java.util.Scanner;
import java.util.Date;
import java.text.SimpleDateFormat;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import java.text.DecimalFormat;
import javax.swing.WindowConstants;
import org.jfree.chart.labels.PieSectionLabelGenerator;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import java.io.*;
import java.text.DecimalFormat;
class Info
{
String name,city;
int age;
int id;
char gender,ans;
Date d_o_vacc;
Scanner sc=new Scanner(System.in);
void addInfo() throws Exception
{
System.out.println("Enter ID:");
id=sc.nextInt();
System.out.println("Enter your name: ");
name=sc.next();
label1:
while(true)
{
System.out.println("Enter your age: ");
age=sc.nextInt();
try
{
if(age<=0)
{
System.out.println("Invalid age: ");
continue label1;
}
else
break label1;
}
catch(ArithmeticException e)
{
System.out.println("Invalid age " + e);
}
}
label2:
while(true)
{
System.out.println("Enter your gender: ");
gender=sc.next().charAt(0);
try
{
if(gender!='F' && gender != 'M')
{
System.out.println("Invalid gender, please enter gender as M or F");
continue label2;
}
else
break label2;
}
catch(Exception ex)
{
System.out.println("Invalid Gender " + ex);
}
}
System.out.println("Enter your city name: ");
city=sc.next();
System.out.println("Enter the date of vaccination");
String vdate=sc.next();
d_o_vacc=new SimpleDateFormat("dd/mm/yyyy").parse(vdate);
System.out.println("Do you have any symptoms of covid-19 for.eg sore throat,fever,loss of smell and taste");
ans=sc.next().charAt(0);
if(ans=='Y')
{
System.out.println("You are not elligible for taking covid vaccine");
}
else
{
System.out.println("Please select the vaccine :");
int vn;
System.out.println("\n \n***VACCINES***");
System.out.println("1.Covishield");
System.out.println("2.Covaccine");
System.out.println("3.Sputnik");
System.out.println("4.Johnsons");
System.out.println("Enter the vaccine number which you would like to take:");
vn=sc.nextInt();
}
System.out.println(ans);
}
void getInfo() throws Exception
{
/*System.out.println("Id= " + id);
System.out.println("Name = " + name);
System.out.println("Age = " + age);
System.out.println("Gender = " + gender);
System.out.println("City = " + city);*/
SimpleDateFormat formatter = new SimpleDateFormat("dd/mm/yyyy");
String d_o_vacc_str = formatter.format(d_o_vacc);
//System.out.println("Vaccine date = " + d_o_vacc);
System.out.println(id+"\t"+name+"\t"+age+"\t"+gender+"\t"+city+"\t"+d_o_vacc_str+"\t"+"corona symptoms=" + ans);
}
static int search_vaccinedetails(VaccineDetails vd[],int vc,String type) throws Exception
{
Scanner sc=new Scanner(System.in);
int i,found=0;
int choice;
System.out.println("Enter the type of searching operation");
System.out.println("1.Search by id");
System.out.println("2.Search by name");
System.out.println("3.Search by age");
System.out.println("4.Search by gender");
System.out.println("5.Search by city");
System.out.println("6.Search by date");
System.out.println("Enter the search number according to your requirement ");
choice=sc.nextInt();
switch(choice)
{
case 1:
int vacc_id;
System.out.println("Enter the id of the person whose vaccine status you want to check" + type);
vacc_id=sc.nextInt();
while(true)
{
for(i=0;i<vc;i++)
{
if(vd[i].id==vacc_id)
{
found=1;
vd[i].getInfo();
}
//if
}//for
return i++;
} //while
//case 1
case 2:
String vacc_name;
System.out.println("Enter the name of the person whose vaccine status you want to check" + type);
vacc_name=sc.next();
while(true)
{
for(i=0;i<vc;i++)
{
if(vd[i].name.equals(vacc_name))
{
found=1;
vd[i].getInfo();
}
//if
} //for
return i++;
}//while
case 3:
int vacc_age;
System.out.println("Enter the age of the person whose vaccine status you want to check" + type);
vacc_age=sc.nextInt();
while(true)
{
for(i=0;i<vc;i++)
{
if(vd[i].age==vacc_age)
{
found=1;
vd[i].getInfo();
}
}//if
//for
return i++;
}//search
case 4:
char vacc_gen;
System.out.println("Enter the gender of the person whose vaccine status you want to check" + type);
vacc_gen=sc.next().charAt(0);
for(i=0;i<vc;i++)
{
if(vd[i].gender==vacc_gen)
{
found=1;
vd[i].getInfo();
}
//if
} //for
//search
case 5:
String vacc_city;
System.out.println("Enter the city of the person whose vaccine status you want to check" + type);
vacc_city=sc.next();
while(true)
{
for(i=0;i<vc;i++)
{
if(vd[i].city.equals(vacc_city))
{
found=1;
vd[i].getInfo();
}
}//if
//for
return i++;
}//search
case 6:
Date vacc_date;
System.out.println("Enter the date of the person whose vaccine status you want to check" + type);
String vc_date=sc.next();
vacc_date=new SimpleDateFormat("dd/mm/yyyy").parse(vc_date);
while(true)
{
for(i=0;i<vc;i++)
{
if(vd[i].d_o_vacc.equals(vc_date))
{
found=1;
vd[i].getInfo();
}
//if
}//for
return i++;
}//while
//switch
default:
System.out.println("Invalid Option");
break;
}
return 0;
}
class BarChartExample extends JFrame {
// private static final long serialVersionUID = 1L;
public BarChartExample(String appTitle) {
super(appTitle);
// Create Dataset
CategoryDataset dataset = createDataset();
//Create chart
JFreeChart chart=ChartFactory.createBarChart(
"Bar Chart Example", //Chart Title
"Year", // Category axis
"Population in Million", // Value axis
dataset,
PlotOrientation.VERTICAL,
true,true,false
);
ChartPanel panel=new ChartPanel(chart);
setContentPane(panel);
}
private CategoryDataset createDataset() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
// int x=20;
if(ans=='Y')
{
// Population in 2005
dataset.addValue(100 , "Not Vaccinated","Ratio");
}
else
// Population in 2010
{
dataset.addValue(10, "Vaccinated","Ratio");
dataset.addValue(90, "NotVaccinated","Ratio");
}
return dataset;
}
}
/*public class PieChartExample extends JFrame {
// private static final long serialVersionUID = 6294689542092367723L;
public PieChartExample(String title) {
super(title);
// Create dataset
PieDataset dataset = createDataset();
// Create chart
JFreeChart chart = ChartFactory.createPieChart(
"Pie Chart Example",
dataset,
true,
true,
false);
//Format Label
PieSectionLabelGenerator labelGenerator = new StandardPieSectionLabelGenerator(
"Vaccine {0} : ({2})", new DecimalFormat("0"), new DecimalFormat("0%"));
//((PiePlot) chart.getPlot()).setLabelGenerator(labelGenerator);
// Create Panel
ChartPanel panel = new ChartPanel(chart);
setContentPane(panel);
}
private PieDataset createDataset() {
Scanner sc=new Scanner(System.in);
char ans;
int a=40;
int b=30;
int c=20;
int d=10;
DefaultPieDataset dataset=new DefaultPieDataset();
dataset.setValue("Covishield", a);
dataset.setValue("Covaccine", b);
dataset.setValue("Sputnik", c);
dataset.setValue("Johnsons", d);
return dataset;
}
}*/
static void sort_vaccinedetails(VaccineDetails vd[],int vc)
{
System.out.println("Select the following options for SORTING...");
Scanner sc=new Scanner(System.in);
int choice;
System.out.println("Enter the type of searching operation");
System.out.println("1.Sort by name");
System.out.println("2.Sort by city");
System.out.println("3.Sort by date");
System.out.println("Enter the search number according to your requirement ");
choice=sc.nextInt();
switch(choice)
{
case 1:
for(int i=0;i<vc-1;i++)
{
for(int j=i+1;j<vc;j++)
{
if(vd[i].name.compareTo(vd[j].name)>0)
{
int st_id=vd[i].id;
vd[i].id=vd[j].id;
vd[j].id=st_id;
String st_name=vd[i].name;
vd[i].name=vd[j].name;
vd[j].name=st_name;
int st_age=vd[i].age;
vd[i].age=vd[j].age;
vd[j].age=st_age;
String st_city=vd[i].city;
vd[i].city=vd[j].city;
vd[j].city=st_city;
Date st_date=vd[i].d_o_vacc;
vd[i].d_o_vacc=vd[j].d_o_vacc;
vd[j].d_o_vacc=st_date;
} // end of if
} // end of i loop
} // end of j loop
System.out.println("PERSON SUCCESSFULLY SORTED BY PERSON NAME...");
break;
case 2:
for(int i=0;i<vc-1;i++)
{
for(int j=i+1;j<vc;j++)
{
if(vd[i].city.compareTo(vd[j].city)>0)
{
int st_id=vd[i].id;
vd[i].id=vd[j].id;
vd[j].id=st_id;
String st_name=vd[i].name;
vd[i].name=vd[j].name;
vd[j].name=st_name;
int st_age=vd[i].age;
vd[i].age=vd[j].age;
vd[j].age=st_age;
String st_city=vd[i].city;
vd[i].city=vd[j].city;
vd[j].city=st_city;
Date st_date=vd[i].d_o_vacc;
vd[i].d_o_vacc=vd[j].d_o_vacc;
vd[j].d_o_vacc=st_date;
} // end of if
} // end of i loop
} // end of j loop
System.out.println("PERSON SUCCESSFULLY SORTED BY PERSON CITY...");
break;
case 3:
for(int i=0;i<vc-1;i++)
{
for(int j=i+1;j<vc;j++)
{
if(vd[i].d_o_vacc.compareTo(vd[j].d_o_vacc)>0)
{
int st_id=vd[i].id;
vd[i].id=vd[j].id;
vd[j].id=st_id;
String st_name=vd[i].name;
vd[i].name=vd[j].name;
vd[j].name=st_name;
int st_age=vd[i].age;
vd[i].age=vd[j].age;
vd[j].age=st_age;
String st_city=vd[i].city;
vd[i].city=vd[j].city;
vd[j].city=st_city;
Date st_date=vd[i].d_o_vacc;
vd[i].d_o_vacc=vd[j].d_o_vacc;
vd[j].d_o_vacc=st_date;
} // end of if
} // end of i loop
} // end of j loop
System.out.println("PERSONS SUCCESSFULLY SORTED BY MANUFACTURING DATE...");
break;
default:System.out.println("INVALID OPTION...");
break;
}// end of switch..case
} // end of update_product()
}
class VaccineDetails extends Info
{
void vaccine() throws Exception
{
addInfo();
Scanner sc=new Scanner(System.in);
getInfo();
} //vaccine()
} //VaccineDetails
class SurveyTest
{
public static void main(String args[]) throws Exception
{
Scanner sc=new Scanner(System.in);
VaccineDetails vd[]=new VaccineDetails[50];
int vc=0,id=0,i;
while(true)
{
System.out.println("*****Operations*****");
System.out.println("1-add");
System.out.println("2-total vaccines");
System.out.println("3-search");
System.out.println("4-sort");
System.out.println("5-display");
System.out.println("6-bar graph");
System.out.println("7-pie chart");
System.out.println("8-exit");
System.out.println("Enter the operation number which you would like to perform:");
int choice=sc.nextInt();
switch(choice)
{
case 1:
vd[id]=new VaccineDetails();
vd[id].addInfo();
id++;
vc++;
break;
case 2:
System.out.println("Total vaccines = " + vc);
break;
case 3:
int vacc_id=VaccineDetails.search_vaccinedetails(vd,vc,"Searched");
for(int j=0;j<vc;j++)
{
if(vacc_id<vc)
{
System.out.println("person is FOUND and details are as follows\n");
System.out.println("ID\t NAME\t AGE\t GENDER\t CITY\t VACC. DATE");
vd[j].getInfo();
}
else
{
System.out.println("Person not found");
break;
}
break;
}
case 4:
VaccineDetails.sort_vaccinedetails(vd,vc);
break;
case 5:
if(vc==0)
{
System.out.println("There is no such person in the database");
}
else
{
System.out.println("person Details are as follows\n");
System.out.println("ID\t NAME\t AGE\t GENDER\t CITY\t VACC. DATE");
for(i=0;i<vc;i++)
{
vd[i].getInfo();
}
}
break;
case 6:
SwingUtilities.invokeAndWait(()->{
BarChartExample example=new BarChartExample("Bar Chart Window");
example.setSize(800, 400);
example.setLocationRelativeTo(null);
//example.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
example.setVisible(true);
});
break;
case 7:
/* SwingUtilities.invokeLater(() -> {
PieChartExample example = new PieChartExample("Pie Chart Example");
example.setSize(800, 400);
example.setLocationRelativeTo(null);
// example.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
example.setVisible(true);
});
break; */
case 8:
System.out.println("End of Program");
System.exit(0);
break;
} // switch
}//while
} //main
}
//SurveyTest