-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoctor.java
More file actions
77 lines (73 loc) · 2.54 KB
/
Copy pathDoctor.java
File metadata and controls
77 lines (73 loc) · 2.54 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
import java.util.*;
import java.io.*;
/**
* This is a Doctor class
* @author Andre Ke
* @author Ryan Su
* @author Wesley Goh
* @author Zilin Weng
* @version Java 17.0.1
*/
class Doctor extends Staff implements ReadFromFileable{
private static final long serialVersionUID = 3L;
int yearsOfExperience;
/**
* Explanation - constructs an instance of Doctor
* @param name - a String that represents the doctor's name
* @param age - a number that represents the doctor's age
* @param gender - a String that represents the doctor's gender
* @param dateOfBirth - a String that represents the doctor's date of birth
* @param phoneNumber - a String that represents the doctor's phone number
* @param emailAddress - a String that represents the doctor's email
* @param yearsOfExperience - a number representing how many years of experience the doctor has
* @param id - a String that represents the doctor's id
* @param password - a String that represents the doctor's password
*/
public Doctor(String name, int age, String gender, String dateOfBirth, String phoneNumber, String emailAddress, int yearsOfExperience, String id, String password){
super(name, age, gender, dateOfBirth, phoneNumber, emailAddress);
super.changeUserUsername(id);
super.changeUserPassword(password);
this.yearsOfExperience = yearsOfExperience;
}
/**
* Explanation - gets the years of experience
* @return a number stored in yearsOfExperience
*/
public int getYearsOfExperience(){
return this.yearsOfExperience;
}
/**
* Explanation - Gets the name of the doctor
* @return the name of the doctor
*/
public String getName(){
return super.getName();
}
/**
* Explanation - reads a file and makes an object ArrayList of the file
* @param fileName - a String representing the file name
* @param clazz - a Class of any object
* @return an ArrayList that can hold any object
* @throws IOException if file name is not found
* @throws ClassNotFoundException if the class being converted to is not found
*/
@Override
public <T> ArrayList<T> readFromFile(String fileName, Class<T> clazz) throws IOException, ClassNotFoundException {
ArrayList<T> objects = new ArrayList<>();
try (FileInputStream fis = new FileInputStream(fileName);
ObjectInputStream ois = new ObjectInputStream(fis)) {
while (true) {
objects.add(clazz.cast(ois.readObject()));
}
}
catch (EOFException e){
return objects;
}
catch (Exception e){
e.printStackTrace();
}
finally{
return objects;
}
}
}