-
Notifications
You must be signed in to change notification settings - Fork 0
/
Patient.java
55 lines (50 loc) · 1.59 KB
/
Patient.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
public class Patient{
private String name;
private int age;
private String illness;
private Patient next, prev;
public Patient(String name, int age, String illness){
this.name = name;
this.age = age;
this.illness = illness;
this.next = null;
this.prev = null;
}
public Patient getNext(){
return next;
}
public Patient getPrev(){
return prev;
}
public String getName(){
return name;
}
public String getIllness(){
return illness;
}
public int getAge(){
return age;
}
public boolean deletePatient(Patient thePatient){
if(this.next == null){
return false;
} else if(this.next.name.equals(thePatient.name)){
this.next = next.next;
this.next.next.prev = this;
return true;
} else {
return this.next.deletePatient(thePatient);
}
}
public void addPatient(Patient newPatient){
if(this.next == null){
this.next = newPatient;
newPatient.prev = this;
} else {
this.next.addPatient(newPatient);
}
}
}
// The addPatient is applied through the most foremost created patient. It takes the newly created patient object in the main method which has been passed into the addPatient function and holds this in place.
//Then method then uses an if branch to test whether the currently held objects nextPatient pointer is currently pointing to null, if it is then it assigns the nextPatient pointer to the newly created object, if
//not then it follows its nextPatient pointer to the next object in the sequence and then by using the dot operator, activates the addPatient method in that object, thus restarting the cycle.