Thread: Class help
View Single Post
  #17 (permalink)  
Old 11-14-2007, 10:05 PM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
public double takeMoneyOut( double amount ) { double totalBalance; totalBalance = balance + overdraftLimit; if( CheckWithdrawal(amount) == false ) { // error message } else { // return totalBalance } } public boolean CheckWithdrawal(boolean checkWithdraw) { if(checkWithdraw > balance ) { return true; } else { return false; } }
In the takeMoneyOut method the argument "amount" is of type double. The if statement in this method is calling the CheckWithdrawal method sending the value of the "amount" variable. So this method call is to a (n apparantly non-existent) method with this type signature:
Code:
boolean CheckWithdrawal(double value)
But the type signature of your CheckWithdrawal method is this:
Code:
boolean CheckWithdrawal(boolean checkWithdraw)
So java cannot find a method with the type signature that your takeMoneyOut method is calling, ie, java cannot find a takeMoneyOut method that takes a (type) double argument. This causes the first compile error:
Code:
error: CheckWithdrawal(boolean) in Account cannot be applied to (double) if( CheckWithdrawal(amount) == false )
In the CheckWithdrawal method the argument "checkWithdraw" is (primitive type) boolean. In the if statement the condition has a type mis-match:
Code:
// boolean double if(checkWithdraw > balance )
which results in the second compile error
Code:
error: operator > cannot be applied to boolean,double if(check > balance )
To compare these two variables they must be the same type. Java is very prissy/picky about variable types. This is to avoid confusion: so everyone is very clear about what types are being passed around/manipulated by the jvm (java virtual machine).
So how to fix this?
Change this
Code:
public boolean CheckWithdrawal(boolean checkWithdraw)
to this
Code:
public boolean CheckWithdrawal(double checkWithdraw)
Reply With Quote