我有两个名为 Patient Class 和 Client Class 的类。我在患者类中创建了方法并在客户端类中调用它们。我想添加一种方法来通过其 id 查找输入的记录并显示它。我的应用程序需要进行哪些更改。程序如下:
患者等级
import javax.swing.*;
public class Patient {
private String patientname;
private String fathername;
private String date;
private int dob;
private static int id = 9000;
private String disease;
private String n;
private double nic;
private String doctorname;
private String prescription;
private String history;
private String searchid;
private int storesearchid;
Patient() {}
public void setPatientInformation() {
id++;
patientname = JOptionPane.showInputDialog("Enter Patient name: ");
fathername = JOptionPane.showInputDialog("Enter Father name of patient: ");
date = JOptionPane.showInputDialog("Enter date of birth : ");
dob = Integer.parseInt(date);
disease = JOptionPane.showInputDialog("Enter disease: ");
n = JOptionPane.showInputDialog("Enter nic no: ");
nic = Integer.parseInt(n);
doctorname = JOptionPane.showInputDialog("Enter your doctor name: ");
prescription = JOptionPane.showInputDialog("Enter description of disease: ");
history = JOptionPane.showInputDialog("Enter history of disease? ");
}
public void showPatientInformation() {
JOptionPane.showMessageDialog(null, "Patient Id" + id + "\nPatient Name: " + patientname + "\nPatient Father Name: " + fathername + "\nPatient Date of birth: " + dob + "\nDisease: " + disease + "\nNIC No:" + nic + "\nDoctor Name: " + doctorname + "\nPrescription: " + prescription + "\nHistory: " + history);
}
public void SearchByPatientId() {
searchid = JOptionPane.showInputDialog("Enter Id of Patient.");
storesearchid = Integer.parseInt(searchid);
if (storesearchid == obj[id]) {
JOptionPane.showMessageDialog(null, "Record Found");
} else {
JOptionPane.showMessageDialog(null, "Record With This Id Not Found.");
}
}
}
客户端类
import javax.swing.*;
public class Client {
public static void main(String[] aa) {
String input;
int i = 0, op = 0;
Patient[] obj = new Patient[50];
obj[i] = new Patient();
while (op != 3) {
input = JOptionPane.showInputDialog("Press 1 for Add new Patient Record.\nPress 2 for search Record by patient ID.\nPress 3 for exit.");
op = Integer.parseInt(input);
switch (op) {
case 1:
JOptionPane.showMessageDialog(null, "Enter New Record");
obj[i].setPatientInformation();
JOptionPane.showMessageDialog(null, "Record added SuccessFully.");
obj[i].showPatientInformation();
break;
case 2:
JOptionPane.showMessageDialog(null, "Search Record By patient ID.");
obj[i].SearchByPatientId();
break;
}
}
}
}