Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sqrt compile error

 
Stephanie Dears
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 21114
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are the x, y, and distance variables defined anywhere?
 
Henry Wong
author
Marshal
Pie
Posts: 21114
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohhh... forgot... is the sqrt() method defined anywhere?
 
diels pei
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use Math.sqrt(),
public double calculateDistanceToOrigin()
{
distance = Math.sqrt(x*x + y *y);
return distance ;
}
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 21114
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic