doubleValue() Correct use?
im trying to use doubleValue method,but not sure how to do so correctly.Passing in array of double's and need to get value,as in method below
public boolean priceChecker( Double[] playerValue)
{
boolean allOk = true;
double totalScore = 0;
for ( int i = 0; i < playerValue.length; i++ ) {
totalScore += playerValue.doubleValue(); //cannot find symbol doubleValue()
}
if (totalScore > 40)
{
allOk = false;
}
else{
allOk = true;
}
return allOk;
}
i have imported import java.lang.Number.*; whci from API i think it extends from..what is the problem.Is this a legal way of using it?
Regards,
Styx21
[723 byte] By [
Styx218a] at [2007-11-27 4:06:34]

if(priceChecker(Double[] playerValue)= true)
{
try
{......
}
Don't see why not, but you should either change it to:
if(priceChecker(Double[] playerValue) == true) //== is the comparison operator, = is assignment
or just
if( priceChecker(Double[] playerValue) ) //don't need to explicitly equate to true or false if returning boolean
> That did it thanks rym82 :)
>
> One more quick q
>
> I want to call method from another method within same
> class as such
>
> if(priceChecker(Double[] playerValue)= true)
>{
>try
>{......
>
> Which is legal way to do this?
>
> 10 duke stars awarded to you :)
if(priceChecker(Double[] playerValue)= true) // compile error, use == for comparison, use = for assignment
// also you don't declare the data type when calling a method
Double[] playerValue;
// do something to initialize and assign value to your Double array
if(priceChecker(playerValue) == true) // can compile now
if(priceChecker(playerValue)) // even better
if(!isPriceOverLimit(playerValue)) // even better (naming convention, meaningful name)
if(!isPriceOverLimit(playerValue)) { // Legal and has no problem
try {
// do something
} catch (Exception e) {
// catch exception
}
}