-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
99 lines (91 loc) · 3.05 KB
/
Copy pathMain.java
File metadata and controls
99 lines (91 loc) · 3.05 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
import java.util.*;
import java.io.*;
/**
* This is the Main class.
* @author Andre Ke
* @author Ryan Su
* @author Wesley Goh
* @author Zilin Weng
* @version Java 17.0.1
*/
class Main {
/**
* Explanation - a static function that writes the an appointment serialized file
* @param appointments - an ArrayList that represents all the appointments
*/
Reception wesley = new Reception("wesley", 17, "male", "2005/12/07", "89123123", "email@email.com", "wesley", "password");
public static void writeAppointments(ArrayList<Appointment> appointments) throws IOException {
try (FileOutputStream os = new FileOutputStream("appointments.ser");
ObjectOutputStream oos = new ObjectOutputStream(os)) {
for (int i = 0; i < appointments.size(); i++) {
oos.writeObject(appointments.get(i));
}
}
catch(Exception e){
e.printStackTrace();
}
}
/**
* Explanation - a static function that writes reports into a serialized file
* @param reports - an ArrayList that represents all reports
*/
public static void writeReports(ArrayList<Report> reports) throws IOException {
try (FileOutputStream os = new FileOutputStream("reports.ser");
ObjectOutputStream oos = new ObjectOutputStream(os)) {
for (int i = 0; i < reports.size(); i++) {
oos.writeObject(reports.get(i));
}
}
catch(Exception e){
e.printStackTrace();
}
}
/**
* Explanation - a static function that writes patients to serialized file
* @param patients - an ArrayList that holds all patients
*/
public static void writePatients(ArrayList<Patient> patients) throws IOException {
try (FileOutputStream fos = new FileOutputStream("patients.ser");
ObjectOutputStream oos = new ObjectOutputStream(fos)) {
for (int i = 0; i < patients.size(); i++) {
oos.writeObject(patients.get(i));
}
}
catch (Exception e){
e.printStackTrace();
}
}
/**
* Explanation - a static function that writes doctors to serialized file
* @param doctors - an ArrayList that holds all doctors
*/
public static void writeDoctors(ArrayList<Doctor> doctors) throws IOException {
try (FileOutputStream fos = new FileOutputStream("doctors.ser");
ObjectOutputStream oos = new ObjectOutputStream(fos)) {
for (int i = 0; i < doctors.size(); i++) {
oos.writeObject(doctors.get(i));
}
}
catch (Exception e){
e.printStackTrace();
}
}
/**
* Explanation - a void function that runs the code
* @throws IOException if files are not found
* @throws ClassNotFoundException if the class being converted is not found
*/
public static void main(String[] args) throws IOException, ClassNotFoundException {
Login in = new Login();
Doctor temp = new Doctor("andre", 17, "male", "2005/12/08", "6475555555", "email@email.com", 1, "andre", "password");
ArrayList<Doctor> tempA = new ArrayList<Doctor>();
tempA.add(temp);
writeDoctors(tempA);
try{
in.displayLogin();
}
catch(Exception e){
System.out.println(e);
}
}
}