gpt4 book ai didi

java - 将 If-Then-Else 语句转换为 If-Then 语句

转载 作者:行者123 更新时间:2023-12-02 04:01:11 25 4
gpt4 key购买 nike

有谁知道如何将 if-then-else 语句转换为 if-then 语句?这太令人困惑了。 else 部分放在哪里并确保结构与 if-then-else 语句相同?感谢您的帮助。

if ((symptom1.equalsIgnoreCase("Yes"))) //fever 3 to 14 days
{
weight = 0.75; //cf

if ((symptom2.equalsIgnoreCase("Yes"))) //rash on any part of the body
{
weight = 0.55; //cf

if ((symptom3.equalsIgnoreCase("Yes"))) //muscle pain
{
weight = 0.45; //cf


if ((symptom4.equalsIgnoreCase("Yes"))) //low blood pressure
{
weight = 0.38; //cf

if ((symptom5.equalsIgnoreCase("Yes"))) //bleeding gum
{
weight = 0.48; //cf

if ((symptom6.equalsIgnoreCase("Yes"))) //bloody feces
{
weight = 0.35; //cf

//severe
newWeight = 0.7 * 0.35; //cf for disease = 0.7 [min=0.35]

String cf = Double.toString(newWeight);

Intent intent = new Intent(resultDengue1.this, resultSevereDengue.class);
intent.putExtra("cfDisease", cf);
startActivity(intent);
}
else //consult doctor
{
weight = 0.3; //cf min
newWeight = 0 * 0.3; //cf for disease = 0

String cf = Double.toString(newWeight);

Intent intent = new Intent(resultDengue1.this, consultDoctor.class);
intent.putExtra("cfDisease", cf);
startActivity(intent);
}
}
//consultDoctor
else
{
weight = 0.3; //cf min
newWeight = 0 * 0.3; //cf for disease = 0

String cf = Double.toString(newWeight);

Intent intent = new Intent(resultDengue1.this, consultDoctor.class);
intent.putExtra("cfDisease", cf);
startActivity(intent);
}
}
//uncomplicated
else
{
newWeight = 0.6 * 0.3; //cf for disease = 0.6 [min=0.3]

String cf = Double.toString(newWeight);

Intent intent = new Intent(resultDengue1.this, resultUncomplicatedDengue.class);
intent.putExtra("cfDisease", cf);
startActivity(intent);
}
}
//consultDoctor
else
{
weight = 0.3; //cf min
newWeight = 0 * 0.3; //cf for disease = 0

String cf = Double.toString(newWeight);

Intent intent = new Intent(resultDengue1.this, consultDoctor.class);
intent.putExtra("cfDisease", cf);
startActivity(intent);
}
}
//consultDoctor
else
{
weight = 0.3; //cf min
newWeight = 0 * 0.3; //cf for disease = 0

String cf = Double.toString(newWeight);

Intent intent = new Intent(resultDengue1.this, consultDoctor.class);
intent.putExtra("cfDisease", cf);
startActivity(intent);
}
}
//absent dengue
else if ((symptom1.equalsIgnoreCase("No"))) //fever 1 to 3 days
{
weight = 0.7; //cf

if ((symptom2.equalsIgnoreCase("No"))) //rash on any part of the body
{
weight = 0.5; //cf

if ((symptom3.equalsIgnoreCase("No"))) //muscle pain
{
weight = 0.4; //cf

if ((symptom4.equalsIgnoreCase("No"))) //low blood pressure
{
weight = 0.3; //cf

if ((symptom5.equalsIgnoreCase("No"))) //bleeding gum
{
weight = 0.4; //cf

if ((symptom6.equalsIgnoreCase("No"))) //bloody feces
{
weight = 0.35; //cf

//absent
newWeight = 0.8 * 0.3; //cf for disease = 0.8 [min=0.3]

String cf = Double.toString(newWeight);

Intent intent = new Intent(resultDengue1.this, resultAbsentDengue.class);
intent.putExtra("cfDisease", cf);
startActivity(intent);
}
else //consultDoctor
{
weight = 0.3; //cf min
newWeight = 0 * 0.3; //cf for disease = 0

String cf = Double.toString(newWeight);

Intent intent = new Intent(resultDengue1.this, consultDoctor.class);
intent.putExtra("cfDisease", cf);
startActivity(intent);
}
}
else //consultDoctor
{
weight = 0.3; //cf min
newWeight = 0 * 0.3; //cf for disease = 0

String cf = Double.toString(newWeight);

Intent intent = new Intent(resultDengue1.this, consultDoctor.class);
intent.putExtra("cfDisease", cf);
startActivity(intent);
}
}
else //consultDoctor
{
weight = 0.3; //cf min
newWeight = 0 * 0.3; //cf for disease = 0

String cf = Double.toString(newWeight);

Intent intent = new Intent(resultDengue1.this, consultDoctor.class);
intent.putExtra("cfDisease", cf);
startActivity(intent);
}
}
else //consultDoctor
{
weight = 0.3; //cf min
newWeight = 0 * 0.3; //cf for disease = 0

String cf = Double.toString(newWeight);

Intent intent = new Intent(resultDengue1.this, consultDoctor.class);
intent.putExtra("cfDisease", cf);
startActivity(intent);
}
}
//consultDoctor
else
{
weight = 0.3; //cf min
newWeight = 0 * 0.3; //cf for disease = 0

String cf = Double.toString(newWeight);

Intent intent = new Intent(resultDengue1.this, consultDoctor.class);
intent.putExtra("cfDisease", cf);
startActivity(intent);
}
}

最佳答案

我假设symptomN的值必须是"is"或“否”。

static boolean check(String[] symptoms, String... values) {
if (values.length != symptoms.length) {
throw new IllegalArgumentException();
}
for (int i = 0; i < symptoms.length; ++i) {
if (!symptoms[i].equalsIgnoreCase(values[i])) {
return false;
}
}
return true;
}

    String[] symptoms = { symptom1, symptom2, symptom3, symptom4, symptom5, symptom6 };

if (check(symptoms, "Yes", "Yes", "Yes", "Yes", "Yes", "Yes")) {
weight = 0.35; //cf

//severe
newWeight = 0.7 * 0.35; //cf for disease = 0.7 [min=0.35]

String cf = Double.toString(newWeight);

Intent intent = new Intent(resultDengue1.this, resultSevereDengue.class);
intent.putExtra("cfDisease", cf);
startActivity(intent);
}
if (check(symptoms, "Yes", "Yes", "Yes", "Yes", "Yes", "No")) {
weight = 0.3; //cf min
newWeight = 0 * 0.3; //cf for disease = 0

String cf = Double.toString(newWeight);

Intent intent = new Intent(resultDengue1.this, consultDoctor.class);
intent.putExtra("cfDisease", cf);
startActivity(intent);
}
if (check(symptoms, "Yes", "Yes", "Yes", "Yes", "No", "Yes")) {
// ...

关于java - 将 If-Then-Else 语句转换为 If-Then 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34866148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com