-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectCorona.java
More file actions
110 lines (98 loc) · 4.63 KB
/
Copy pathProjectCorona.java
File metadata and controls
110 lines (98 loc) · 4.63 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
import java.io.*;
import java.util.Scanner;
public class ProjectCorona {
public static void main(String[] args) throws IOException{
File file = new File("person_data_corona.txt");
try(
Scanner input = new Scanner(file);
){
while(input.hasNext()){
input.next();
String name = input.nextLine().trim();
System.out.println(name);
input.next();
int age = input.nextInt();
System.out.println(age);
input.next(); input.next();
String pno = input.nextLine().trim();
input.next();
System.out.println(pno);
boolean health_issues;
String healthy_str = input.nextLine();
health_issues = (healthy_str.contains("Yes"))? true : false;
System.out.println(health_issues);
if(!health_issues){
Person person = new Healthy();
person.setAge(age);
person.setName(name);
person.setPhone_no(pno);
createReport(person);
if(!input.hasNext()) break;
continue;
}
boolean travelled = input.nextLine().contains("Yes")?true:false;
String test1 = input.nextLine();
String [] symptoms = test1.substring(test1.indexOf(':') + 1).split(",");
for(int i = 0; i < symptoms.length; i++)
symptoms[i] = symptoms[i].trim();
boolean pre_med_cond = input.nextLine().contains("Yes")?true:false;
boolean severe = input.nextLine().contains("Yes")?true:false;
input.next(); input.next(); input.next(); input.next();
int days_ill = input.nextInt();
boolean improvement = input.nextLine().contains("Yes")?true:false;
boolean nearby_cov = input.nextLine().contains("Yes")?true:false;
Person p = new Ill(symptoms, severe, pre_med_cond, improvement, days_ill, travelled, nearby_cov);
if(((Ill)p).probableCoronaVirus()){
Person p2 = new COVID_19((Ill)p);
p2.setName(name);
p2.setAge(age);
p2.setPhone_no(pno);
createReport(p2);
}
else{
Person p3 = new CommonColdOrFlu((Ill)p);
p3.setName(name);
p3.setAge(age);
p3.setPhone_no(pno);
createReport(p3);
}
if(!input.hasNext()) break;
input.nextLine();
}
}
}
public static void createReport(Person p) throws IOException{
String nameOfFile []= p.getName().split(" ");
if(p instanceof Healthy){
try(PrintWriter report = new PrintWriter("Result\\"+nameOfFile[0]+"_"+nameOfFile[1])){
report.println(((Healthy)p).toString().toUpperCase());
report.println();
report.println("What to eat for wellness and health? ");
report.println(((Healthy)p).whatToEat());
report.println();
report.println("OK, good to go, but \n\"PREVENTION IS BETTER THAN CURE\"");
report.println(((Healthy)p).preventiveMeasures());
}
}
else if(p instanceof COVID_19){
try(PrintWriter report = new PrintWriter("Result\\"+nameOfFile[0]+"_"+nameOfFile[1])){
report.println(p.toString().toUpperCase());
report.println();
report.println(((COVID_19)p).advice());
report.println();
report.println("You may have to take some PREVENTIVE MEASURES: ");
report.println(((COVID_19)p).preventiveMeasures());
}
}
else if(p instanceof CommonColdOrFlu){
try(PrintWriter report = new PrintWriter("Result\\"+nameOfFile[0]+"_"+nameOfFile[1])){
report.println(p.toString().toUpperCase());
report.println();
report.println(((CommonColdOrFlu)p).advice());
report.println();
report.println("You may have to take some PREVENTIVE MEASURES: ");
report.println(((CommonColdOrFlu)p).preventiveMeasures());
}
}
}
}