# sqrt compile error

Stephanie Dears
Ranch Hand
Posts: 43
Ken, Jim...I'M BAAAAAAACK!!

I hope this next assignment is better than the last. This one is a hummer...robots...my mind just spins typing the word.

To begin...I haven't even gotten into the meat of the multiple classes involved.

I have a class called Coordinates.

Inside I have a method:

I get "cannot find symbol".

What do you think?

Steph

Henry Wong
author
Marshal
Posts: 21493
84
Are the x, y, and distance variables defined anywhere?

Henry Wong
author
Marshal
Posts: 21493
84
Ohhh... forgot... is the sqrt() method defined anywhere?

diels pei
Greenhorn
Posts: 1
you can use Math.sqrt(),
public double calculateDistanceToOrigin()
{
distance = Math.sqrt(x*x + y *y);
return distance ;
}

Jim Yingst
Wanderer
Sheriff
Posts: 18671
Hi Steph.

[Steph]: I get "cannot find symbol".

And, immediately after these words, it should tell you which symbol, on which line of the file, it's talking about. This would be useful information to know.

Stephanie Dears
Ranch Hand
Posts: 43
Jim,

I knew you would be glad to hear from me.

Diels mentioned using Math.sqrt...I did that and received no error. On to the next step. We can only hope.

Thanks Jim and Diels.

Henry,

Yes, the x, y, and distance were defined. How do you define a sqrt? I looked in my books and on the net and couldn't find anything.

Henry Wong
author
Marshal
Posts: 21493
84
Originally posted by Stephanie Dears:

Yes, the x, y, and distance were defined. How do you define a sqrt? I looked in my books and on the net and couldn't find anything.

Didn't you just mentioned that you are going to use the method that is defined in the Math class?

Henry

Jim Yingst
Wanderer
Sheriff
Posts: 18671
[Steph]: How do you define a sqrt?

Probably you just want to use Math.sqrt() as Diels suggested. It's possible to define your own, but most likely that's well outside the scope of this problem. If you really want to know the details, you can google "Newton's method" and "square root" together to get a lot of discussion of the most common technique. But only do that if you're sure you can't just use a pre-existing method like Math.sqrt().
[ December 05, 2005: Message edited by: Jim Yingst ]