That’s my confirmBooking method and im trying to check whether age is equal to a student or child so i can apply discounts wherever needed using an if statement. Also my boolean value is because i checked whether the age given was between some given numbers to determine whether it was a child or student. I get this error Customer.java [line: 41]
line 41 is if(age == (isStudent() || isChild()))
Error: The operator == is undefined for the argument type(s) int,
boolean
Could someone explain why?
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
Primitive types are compared with
==. You can’t invoke theequalsmethod on a primitive type. Primitive types are not objects. Another error is that you are directly comparingbooleanandintvalue. They are not compatible.