HOWTO · Java
アレルギー教室 in Java
このチュートリアルでは、患者にアレルギーがあるかどうかを Java でチェックする allergy という名前のクラスを作成する方法を示します。
このチュートリアルでは、Java で患者にアレルギーがあるかどうかをチェックする Allergy という名前のクラスを作成する方法を示します。
Java でアレルギー クラスを作成する
アレルギー クラスとは、患者のアレルギーを検出できるクラスを意味します。 Java でアレルギー用のクラスを作成できます。このクラスは、アレルギー名の重症度を設定および取得します。
このシステムをサポートするには、患者のアレルギーに基づいて、または患者にアレルギーや他の病気があるかどうかに基づいて、システムを実行するための他のクラスを作成する必要があります。
患者のアレルギーを検出し、手順を確認するシステムを作成しましょう。
- 4つのクラスを作成する必要があります。
- 最初のクラスは、アレルギーに関する情報を設定および取得する
allergyクラスです。 - 2 番目のクラスは
patientクラスで、患者の名前、年齢、アレルギーを設定および取得するために使用されます。 - 3 番目のクラスは、患者がアレルギー以外の別の病気にかかっている場合に使用される
病気クラスです。 - 最後の 4 番目のクラスは
driverクラスで、ユーザー情報と症状を追加し、患者の結果を表示するために使用されます。
上記のシステムを Java で実装してみましょう。
まず、AllergyClass.java:
package delftstack;
public class AllergyClass {
private String Allergy_Name;
private String Allergy_Severity;
private String Allergy_Symptoms;
public String GetAllergyName() {
return Allergy_Name;
}
public void SetAllergyName(String Allergy_Name) {
this.Allergy_Name = Allergy_Name;
}
public void SetAllergySymptom(String Allergy_Symptoms) {
this.Allergy_Symptoms = Allergy_Symptoms;
}
public String GetAllergySymptom() {
return Allergy_Symptoms;
}
public String GetSeverity() {
return Allergy_Severity;
}
public void SetSeverity(String Allergy_Severity) {
this.Allergy_Severity = Allergy_Severity;
}
}
allergy クラスは、アレルギーの名前、重症度、および症状を設定および取得するために使用されます。 PatientClass.java:
package delftstack;
import java.util.List;
public class PatientClass {
private String Patient_Name;
private int Patient_Age;
private List<AllergyClass> Allergy_List;
private List<DiseaseClass> Disease_List;
public String GetPatientName() {
return Patient_Name;
}
public void SetPatientName(String Patient_Name) {
this.Patient_Name = Patient_Name;
}
public int GetPatientAge() {
return Patient_Age;
}
public void SetPatientAge(int Patient_Age) {
this.Patient_Age = Patient_Age;
}
public List<AllergyClass> GetAllergyList() {
return Allergy_List;
}
public void SetAllergyList(List<AllergyClass> Allergy_List) {
this.Allergy_List = Allergy_List;
}
public List<DiseaseClass> GetDiseaseList() {
return Disease_List;
}
public void SetDiseaseList(List<DiseaseClass> Disease_List) {
this.Disease_List = Disease_List;
}
}
patient クラスは、患者の名前と年齢を設定および取得し、アレルギーまたは疾患を割り当てるために使用されます。 DiseaseClass.java:
package delftstack;
public class DiseaseClass {
private String Disease_Name;
private String Disease_Severity;
private String Disease_Symptoms;
public String GetDiseaseName() {
return Disease_Name;
}
public void SetDiseaseName(String Disease_Name) {
this.Disease_Name = Disease_Name;
}
public void SetDiseaseSymptom(String Disease_Symptoms) {
this.Disease_Symptoms = Disease_Symptoms;
}
public String GetDiseaseSymptom() {
return Disease_Symptoms;
}
public String GetSeverity() {
return Disease_Severity;
}
public void SetSeverity(String Disease_Severity) {
this.Disease_Severity = Disease_Severity;
}
}
disease クラスは allergy クラスと同じ操作を実行します。 これは、患者の症状がアレルギーに関連していない場合のオプションのクラスです。 現在、main クラスは Patient_Health_Info.java です。
package delftstack;
import java.util.ArrayList;
import java.util.List;
public class Patient_Health_Info {
public static void main(String[] args) {
// Create an instance of patient
PatientClass Demo_Patient = new PatientClass();
Demo_Patient.SetPatientName("Sheeraz");
Demo_Patient.SetPatientAge(28);
// Create an instance of Allergy
AllergyClass First_Allergy = new AllergyClass();
First_Allergy.SetAllergyName("Peanuts");
First_Allergy.SetAllergySymptom("Swelling/Chocking");
First_Allergy.SetSeverity("Severe");
// Create another instance of Allergy if a patient has multiple allergies
AllergyClass Second_Allergy = new AllergyClass();
Second_Allergy.SetAllergyName("Eggs");
Second_Allergy.SetAllergySymptom("Skin inflammation/Nasal congestion");
Second_Allergy.SetSeverity("Medium");
// Add Allergies to a list
List<AllergyClass> Allergy_List = new ArrayList<AllergyClass>();
Allergy_List.add(First_Allergy);
Allergy_List.add(Second_Allergy);
// Assign Allergies to the Patient.
Demo_Patient.SetAllergyList(Allergy_List);
String Patient_Diagnosis = PatientDiagnosis(Demo_Patient);
// Add Diseases to a list if present.
List<DiseaseClass> Disease_List = new ArrayList<DiseaseClass>();
// No diseases added
System.out.println("The Patient's Name is: " + Demo_Patient.GetPatientName());
System.out.println("The Patient's Age is: " + Demo_Patient.GetPatientAge());
System.out.println("The Patient has been diagnosed with :: " + Patient_Diagnosis);
if (Patient_Diagnosis == "Allergy") {
for (AllergyClass Patient_Allergy : Allergy_List) {
System.out.println("The Patient has a/an " + Patient_Allergy.GetAllergyName() + " allergy"
+ " with the symptoms of " + Patient_Allergy.GetAllergySymptom()
+ " and the allergy is " + Patient_Allergy.GetSeverity());
}
} else if (Patient_Diagnosis == "Disease") {
for (DiseaseClass Patient_Disease : Disease_List) {
System.out.println("The Patient has " + Patient_Disease.GetDiseaseName() + " Disease"
+ " with the symptoms of " + Patient_Disease.GetDiseaseSymptom()
+ " and the allergy is " + Patient_Disease.GetSeverity());
}
}
}
public static String PatientDiagnosis(PatientClass patient) {
if (patient.GetAllergyList().size() > 0) {
return "Allergy";
} else if (patient.GetDiseaseList().size() > 0) {
return "Disease";
}
return null;
}
}
この main クラスは、患者のアレルギーまたは疾患に関する情報を挿入および取得するために使用されます。 また、患者にアレルギーやその他の病気があるかどうかも判断します。 システム全体を実行して、出力を見てみましょう。
The Patient's Name is: Sheeraz
The Patient's Age is: 28
The Patient has been diagnosed with :: Allergy
The Patient has a/an Peanuts allergy with the symptoms of Swelling/Chocking and the allergy is Severe
The Patient has a/an Eggs allergy with the symptoms of Skin inflammation/Nasal congestion and the allergy is Medium