用Java写一份复杂代码要求实现:1、登记病人信息。2、诊断病情。3、体质检测。4、通过药方开药。5、说明使用方法
时间: 2024-06-08 13:05:24 浏览: 115
java程序 病人病例管理系统
3星 · 编辑精心推荐
以下是一份基于Java的代码,实现了登记病人信息、诊断病情、体质检测、通过药方开药、说明使用方法的功能:
```java
import java.util.Scanner;
public class MedicalSystem {
private static int patientCount = 0;
private static Patient[] patients = new Patient[100];
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int choice;
do {
System.out.println("请选择要进行的操作:");
System.out.println("1. 登记病人信息");
System.out.println("2. 诊断病情");
System.out.println("3. 体质检测");
System.out.println("4. 通过药方开药");
System.out.println("5. 说明使用方法");
System.out.println("0. 退出系统");
choice = scanner.nextInt();
switch (choice) {
case 1:
registerPatient(scanner);
break;
case 2:
diagnosePatient(scanner);
break;
case 3:
checkPhysique(scanner);
break;
case 4:
prescribeMedicine(scanner);
break;
case 5:
explainUsage();
break;
case 0:
System.out.println("感谢使用医疗系统!");
break;
default:
System.out.println("无效的选择,请重新输入。");
}
} while (choice != 0);
}
private static void registerPatient(Scanner scanner) {
System.out.println("请输入病人姓名:");
String name = scanner.next();
System.out.println("请输入病人性别:");
String gender = scanner.next();
System.out.println("请输入病人年龄:");
int age = scanner.nextInt();
System.out.println("请输入病人联系电话:");
String phone = scanner.next();
patients[patientCount] = new Patient(patientCount + 1, name, gender, age, phone);
System.out.println("病人信息登记成功,病历号为:" + (patientCount + 1));
patientCount++;
}
private static void diagnosePatient(Scanner scanner) {
System.out.println("请输入病历号:");
int id = scanner.nextInt();
if (id > 0 && id <= patientCount) {
Patient patient = patients[id - 1];
System.out.println("请输入病情描述:");
String symptoms = scanner.next();
Diagnosis diagnosis = new Diagnosis(symptoms);
String result = diagnosis.getResult();
System.out.println(patient.getName() + "的诊断结果为:" + result);
} else {
System.out.println("无效的病历号,请重新输入。");
}
}
private static void checkPhysique(Scanner scanner) {
System.out.println("请输入病历号:");
int id = scanner.nextInt();
if (id > 0 && id <= patientCount) {
Patient patient = patients[id - 1];
System.out.println("请输入身高(单位:米):");
double height = scanner.nextDouble();
System.out.println("请输入体重(单位:千克):");
double weight = scanner.nextDouble();
Physique physique = new Physique(height, weight);
String result = physique.getResult();
System.out.println(patient.getName() + "的体检结果为:" + result);
} else {
System.out.println("无效的病历号,请重新输入。");
}
}
private static void prescribeMedicine(Scanner scanner) {
System.out.println("请输入病历号:");
int id = scanner.nextInt();
if (id > 0 && id <= patientCount) {
Patient patient = patients[id - 1];
System.out.println("请输入药方:");
String prescription = scanner.next();
Medicine medicine = new Medicine(prescription);
String usage = medicine.getUsage();
System.out.println(patient.getName() + "的药方为:" + prescription);
System.out.println("使用方法为:" + usage);
} else {
System.out.println("无效的病历号,请重新输入。");
}
}
private static void explainUsage() {
System.out.println("使用方法:");
System.out.println("1. 登记病人信息:输入病人姓名、性别、年龄、联系电话,系统会自动生成病历号。");
System.out.println("2. 诊断病情:输入病历号和病情描述,系统会根据病情描述生成诊断结果。");
System.out.println("3. 体质检测:输入病历号、身高和体重,系统会根据身高和体重生成体检结果。");
System.out.println("4. 通过药方开药:输入病历号和药方,系统会根据药方生成使用方法。");
System.out.println("5. 说明使用方法:显示系统的使用方法。");
System.out.println("0. 退出系统:退出医疗系统。");
}
}
class Patient {
private int id;
private String name;
private String gender;
private int age;
private String phone;
public Patient(int id, String name, String gender, int age, String phone) {
this.id = id;
this.name = name;
this.gender = gender;
this.age = age;
this.phone = phone;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public int getAge() {
return age;
}
public String getPhone() {
return phone;
}
}
class Diagnosis {
private String symptoms;
public Diagnosis(String symptoms) {
this.symptoms = symptoms;
}
public String getResult() {
// 根据病情描述生成诊断结果的逻辑
return "感冒";
}
}
class Physique {
private double height;
private double weight;
public Physique(double height, double weight) {
this.height = height;
this.weight = weight;
}
public String getResult() {
// 根据身高和体重生成体检结果的逻辑
return "体重正常";
}
}
class Medicine {
private String prescription;
public Medicine(String prescription) {
this.prescription = prescription;
}
public String getUsage() {
// 根据药方生成使用方法的逻辑
return "每日三次,每次一粒,饭后服用";
}
}
```
该代码中,使用了面向对象的思想,将病人、诊断、体检、药方等概念抽象为类,并在主程序中实现了对这些类的调用。用户可以通过输入不同的选项来执行相应的操作,如登记病人信息、诊断病情、体质检测、通过药方开药、说明使用方法等。
阅读全文