This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2017/1/16

bad operand type for binary operator

divinity divinity

2017/1/16

#
Hi and good morning people I am doing a java pizza restaurant ordering program . and I am getting this error in this part of the program: bad operand type for binary operator here is the code it offers seven topping for small, medium, large and family size of pizza. I am giving it a try by using a for loop so that it can run seven time just to see how it work. I am not finish as yet. the problem is if any one of the topping is choosen, the cost will be assigned to it. what I am trying to is adding the topping to the cost and reassigning it to the topping cost but I am getting this error bad operand type for binary operator. can you tell me what and where and how it can be fixed.
public double getToppingCost(){
          
          double toppingCost =0.0;
          
          for(int i=0; i <=7; i++){
              
              if(tomato.isSelected()){
                   toppingCost += tomato;: the error is here. bad operand type for binary operator
                  
                  return toppingCost;
              }
Super_Hippo Super_Hippo

2017/1/16

#
It seems like 'tomato' is a object. You can't add an object to a double. You might need a method in the class which the tomato belongs to and call a 'getCost' method (or something like that) on it which returns the cost of the tomato (as a double).
divinity divinity

2017/1/16

#
thank u super_hippo and happy new year to you and yours
You need to login to post a reply.