-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatient.java
More file actions
68 lines (60 loc) · 1.87 KB
/
Copy pathPatient.java
File metadata and controls
68 lines (60 loc) · 1.87 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
public class Patient {
private String patientId;
private String name;
private int age;
private String diagnosis;
public Patient(String patientId, String name, int age, String diagnosis){
if(age < 0){
throw new IllegalArgumentException("Age cannot be negative");
}
if (diagnosis.isEmpty()){
throw new IllegalArgumentException("Diagnosis cannot be null or empty");
}
this.patientId = patientId;
this.age = age;
this.name = name;
this.diagnosis = diagnosis;
}
public String getPatientId(){
return patientId;
}
public void setPatientId(String patientId){
this.patientId = patientId;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public int getAge(){
return age;
}
public void setAge(int age){
if (age<0){
throw new IllegalArgumentException("Age cannot be negative");
}
this.age = age;
}
public String getDiagnosis(){
return diagnosis;
}
public void setDiagnosis(String diagnosis){
if(diagnosis.isEmpty()){
throw new IllegalArgumentException("Diagnosis cannot be null or empty");
}
this.diagnosis = diagnosis;
}
public void updateDiagnosis(String newDiagnosis){
if(newDiagnosis.isEmpty()){
throw new IllegalArgumentException("Diagnosis cannot be null or empty");
}
this.diagnosis = newDiagnosis;
System.out.println("Diagnosis updated successfully to " + newDiagnosis);
}
@Override
public String toString(){
return
"Patient ID: " + patientId + "\nName: " + name + "\nAge: " + age + "\nDiagnosis: " + diagnosis;
}
}