gpt4 book ai didi

java - 如何将字符更改为 boolean 值?

转载 作者:行者123 更新时间:2023-12-01 12:23:34 26 4
gpt4 key购买 nike

我的问题是如何将字符更改为 boolean 值。例如我有两堂课

一个是仅具有出血历史方法和信息的患者类别:

Public class Patient {

private static String name;
private static boolean bleedingHistory = true;
private String answer;
private double ureaLevel;
private double proLevel;


public Patient()
{
String name = "unknown";
double ureaLevel = 0.0;
double proLevel = 0.0;
boolean bleedingHistory = false;

}

public Patient (String inName, boolean inBleedingHistory)
{
if (name != "" || bleedingHistory == true)
{
name = inName;
bleedingHistory = inBleedingHistory;

}

else
{
name = "unknown";
bleedingHistory = false;
}

proLevel = 0.0;
ureaLevel = 0.0;
}
public boolean getBleedingHistory()
{
return bleedingHistory;

}

public void setBleedingHistory(boolean inBleedingHistory)
{

bleedingHistory = inBleedingHistory;
}

另一个类的一部分调用 Patientcheck,要求用户输入患者是否有出血史:

System.out.print("Does the patient has a history of bleeding(Yes or No)?: ");
char inBleedingHistory;
do
{
inBleedingHistory = sc.next().charAt(0);
if (inBleedingHistory != 'n' && inBleedingHistory != 'N' && inBleedingHistory != 'y' && inBleedingHistory != 'Y')
{System.out.println("Invalid answer, please enter YES or NO: ");

sc.nextLine();
}

}while (inBleedingHistory != 'n' && inBleedingHistory != 'N' && inBleedingHistory != 'y' && inBleedingHistory != 'Y');

pat1 = new Patient (inName, inBleedingHistory);

我知道我的患者检查记录出血史的部分是错误的,但我能做些什么来纠正它?谢谢

最佳答案

pat1 = new Patient(inName, (inBleedingHistory=='y' || inBleedingHistory=='Y'));

关于java - 如何将字符更改为 boolean 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26503995/

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