Why is this method return 0
I have a class with instance variable price.
I have a method getThePrice() which gets this just fine.
However I have decided to use another method getThePrice(int weight) and simply pass zero as an argument for those products that need not be weighed. The problem is that the method I have written does not work, I am a loss as to what I have done wrong. Any help would be appreciated:
This is the method that does not work:
Code:
public int getThePrice(int weighedObject){
if(weighedObject == 0){
return price;
}
else if(weighedObject > 0){
return price * weighedObject;
}
return price;
}
But when I use this one everything works fine. I am sure it is something wrong with the method I have written:
Code:
public int getThePrice(){
return price;
}