这是我的confirmBooking方法,我试图检查age是否等于学生或孩子,所以我可以使用if语句在需要的地方应用折扣。此外,我的布尔值是因为我检查给定的年龄是否在一些给定的数字之间,以确定它是一个孩子还是学生。我得到这个错误Customer.java [行:41] 线41 if(age == (isStudent() || isChild()))
显示int的错误等于布尔对象
Error: The operator == is undefined for the argument type(s) int, boolean
有人能解释一下为什么?
public double confirmBooking(){
double standardTicketPrice = 56.0;
double standardMealPrice = 30.0;
if(age == (isStudent() || isChild())){
return standardTicketPrice/2.0;
}else{
return standardTicketPrice * (20.0/100.0);
}
if(age.equals(isChild())){
return standardMealPrice/2.0;
}else{
return standardMealPrice * (10.0/100.0);
}
}// end method confirmBooking
你可以给更多的代码,与isChild()和isStudent()? – COD3BOY
@Sanjay public boolean isChild(){ if(age> = 5 && age <= 16){ return true; } else { return false; } } public boolean isStudent(){ if(id == true){ return true; } else { return false; } } – M1N33