-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
88 lines (82 loc) · 3.61 KB
/
Main.java
File metadata and controls
88 lines (82 loc) · 3.61 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
import treatments.Injection;
import treatments.Pills;
import treatments.Therapy;
import treatments.Treatment;
import patients.Patient;
import java.util.*;
public class Main {
public static void main(String[] rgs) {
Scanner stdin = new Scanner(System.in);
System.out.println("Hello, user.");
System.out.println("We will start by setting your parameters");
System.out.println("Please input your name: ");
String name = stdin.nextLine();
System.out.println("Please input your age: ");
int age = stdin.nextInt();
Patient patient = new Patient(name, age);
System.out.println("The patient was successfully created!");
System.out.println(patient); // the toString function in the Patient class uses a try catch exception bloc
System.out.println("How many treatments does this patient have?");
int n = stdin.nextInt();
String choice, doctor, medicine_name, description, needleType, needleVolume, therapist;
int nbTimes, nbDays, postponeDays;
double cost;
for (int i = 0; i < n; i++) {
System.out.println("Treatment number: " + (i + 1));
System.out.println("What's the name of the doctor who prescribed this treatment?");
doctor = stdin.next();
System.out.println("How many times a day should this treatment be taken?");
nbTimes = stdin.nextInt();
System.out.println("For how many days?");
nbDays = stdin.nextInt();
System.out.println(
"Once this treatment is taken, how many days should the patient wait before taking it again?");
postponeDays = stdin.nextInt();
System.out.println("How much is this treatment going to cost the patient?");
cost = stdin.nextDouble();
System.out.println("What kind of treatment is it?\n1-Pills\n2-Injections\nelse-Physical therapy");
choice = stdin.next();
try {
if (Integer.parseInt(choice) == 1) {
System.out.println("What's the name of the pills?");
medicine_name = stdin.next();
System.out.println("Describe the pills:");
description = stdin.next();
patient.addTreatment(new Pills(doctor, nbTimes, nbDays, postponeDays, medicine_name, description));
} else if (Integer.parseInt(choice) == 2) {
System.out.println("What's the name of the injection?");
medicine_name = stdin.next();
System.out.println("Describe the injection:");
description = stdin.next();
System.out.println("What is the type of the needle used for this injection?");
needleType = stdin.next();
System.out.println("What is its volume?");
needleVolume = stdin.next();
patient.addTreatment(new Injection(doctor, nbTimes, nbDays, postponeDays, medicine_name,
description, needleType, needleVolume));
}
else {
throw new NumberFormatException() ;
}
} catch (NumberFormatException e) {
System.out.println("What's the name of the therapist who will perform it?");
therapist = stdin.next();
patient.addTreatment(new Therapy(doctor, nbTimes, nbDays, postponeDays, therapist));
} finally {// Finally bloc
patient.getTreatments().get(patient.getTreatments().size()-1).setCost(cost); // This line was used in this
// non efficient way on
// purpose to call the "set"
// method, and the "get"
// method as the getters and
// setters were not
// frequently used in this
// project.
}
}
System.out.println("We have registered all the treatments. Here is an overview of the patient: ");
System.out.println(patient);
System.out.println("Here is an overview of their treatments: ");
patient.displayAllTreatments();
stdin.close();
}
}