我为我的作业编写了一个代码,它假设接收到糖水平和状况的输入,然后我将确定糖水平
我认为我的投入是: 输入您的血糖水平:70 1.空腹 2.餐后2小时 输入您的条件:禁食 正常
但是它没有打印出来正常,它就在这里停止: 输入您的血糖水平:70 1.空腹 2.餐后2小时 输入您的条件:禁食 建立成功(总时间:9秒)
public class SugarLevel {
private double sugarLevel;
private String condition;
private String classification;
public void setSugarLevel(double sL){
sugarLevel =sL;
}
public Double getSugarLevel(){
return sugarLevel;
}
public void setCondition(String c){
condition = c;
}
public String getCondition(){
return condition;
}
public String calculateSugarLevelFasting(){
if(sugarLevel < 70){
classification = "Low";
}
else{
if(sugarLevel >= 70 && sugarLevel <=110){
classification = "Normal";
}
else{
if(sugarLevel >= 111 && sugarLevel <= 125){
classification = "Pre-Diabetes";
}
else{
if(sugarLevel > 125){
classification = "Diabetes";
}
}
}
}
return classification;
}
public String calculateSugerLevel2HAfterMeal(){
if(sugarLevel < 70){
classification = "Low";
}
else{
if(sugarLevel >= 70 && sugarLevel <=140){
classification = "Normal";
}
else{
if(sugarLevel >= 141 && sugarLevel <= 160){
classification = "Pre-Diabetes";
}
else{
if(sugarLevel > 160){
classification = "Diabetes";
}
}
}
}
return classification;
}
}
import java.util.Scanner;
public class HealhtMonitoringSystem {
public static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
/*Sugar Level*/
SugarLevel sugar = new SugarLevel();
String c = null;
System.out.print("Enter Your Blood Sugar Level :");
double sl = scan.nextDouble();
sugar.setSugarLevel(sl);
sugar.getSugarLevel();
System.out.println("1. Fasting");
System.out.println("2. 2 Hours After Meal");
System.out.print("Enter your condition : ");
String choice = scan.next();
sugar.setCondition(choice);
sugar.getCondition();
if(choice == "Fasting"){
c =sugar.calculateSugarLevelFasting();
System.out.println(c);
}
else{
if(choice == "2 Hours After Meal"){
c = sugar.calculateSugerLevel2HAfterMeal();
System.out.println(c);
}
}
}
}