public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入您的症状(多个症状之间用逗号分隔):"); String symptomsString = scanner.nextLine(); List<String> symptoms = Arrays.asList(symptomsString.split(",")); System.out.println("请输入您的流行病学史:"); String history = scanner.nextLine(); System.out.println(DiagnosisChecker.diagnose(symptoms, history)); } }基于决策表方法实现测试,用Java代码编写
时间: 2024-02-29 19:57:18 浏览: 79
java输入语句scanner用法讲解.pdf
好的,这是一个基于决策表方法实现测试的Java代码:
```java
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入您的症状(多个症状之间用逗号分隔):");
String symptomsString = scanner.nextLine();
List<String> symptoms = Arrays.asList(symptomsString.split(","));
System.out.println("请输入您的流行病学史:");
String history = scanner.nextLine();
System.out.println(DiagnosisChecker.diagnose(symptoms, history));
}
}
class DiagnosisChecker {
static String diagnose(List<String> symptoms, String history) {
Map<List<String>, String> decisionTable = new HashMap<>();
decisionTable.put(Arrays.asList("发热", "咳嗽", "喉咙疼", "流感病史"), "流感");
decisionTable.put(Arrays.asList("发热", "咳嗽", "喉咙疼"), "感冒");
decisionTable.put(Arrays.asList("咳嗽", "气喘", "胸痛"), "支气管炎");
decisionTable.put(Arrays.asList("呼吸困难", "胸痛", "咳嗽", "痰液带血"), "肺炎");
decisionTable.put(Arrays.asList("腹泻", "腹痛", "恶心", "呕吐"), "肠胃炎");
decisionTable.put(Arrays.asList("腹泻", "腹痛", "恶心"), "肠炎");
decisionTable.put(Arrays.asList("头痛", "恶心", "呕吐"), "偏头痛");
for (List<String> condition : decisionTable.keySet()) {
if (symptoms.containsAll(condition) && history.contains("疫区")) {
return "您可能感染了" + decisionTable.get(condition) + ",请尽快前往医院就诊!";
}
}
return "根据您的症状和流行病学史,暂时无法确定您的疾病,请咨询医生。";
}
}
```
这个程序会要求用户输入症状和流行病学史,然后根据预先定义的决策表来诊断可能的疾病。如果输入的症状和流行病学史符合某个条件,就会返回相应的疾病名称,否则返回无法确定。注意,这个程序只是一个简单的示例,实际的决策表可能会更加复杂。
阅读全文