我的問題是如何將char轉換爲布爾值。比如我有2類如何將char轉換爲布爾值?
一個是隻有bleedinghistory方法和病人的信息類:
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);
我知道我的病歷檢查部分的歷史出血是錯誤的,但我能做些什麼來糾正它?感謝
'布爾charIsY =(CH == 'Y' || CH == 'Y');' – khelwood 2014-10-22 09:14:19