Reputation: 41
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
Upvotes: 1
Views: 3088
Reputation: 60
You can't compare int
and double
.
You need just if(isStudent() || isChild())
(inside these functions you already "checked whether the age given was between some given numbers").
Upvotes: 0
Reputation: 2653
Try this instad of if(age == (isStudent() || isChild())
if(true == ((isStudent() || isChild()). isStudent and isChild methods return type shold be boolean.
You can't apply equal method from integer.
instead of if(age.equals(isChild())) apply similer way as if(true == ((isStudent() || isChild())
Upvotes: 1
Reputation: 692231
int
and boolean
are two different types, and can never be equal to each other.
An int has 2^32 values, whereas a boolean has only two : true
and false
.
Your methods should be isStudent(int age)
and isChild(int age)
. They would return true or false depending on the age argument.
Upvotes: 1
Reputation: 47403
Primitive types are compared with ==
. You can't invoke the equals
method on a primitive type. Primitive types are not objects. Another error is that you are directly comparing boolean
and int
value. They are not compatible.
Upvotes: 3