I’m using the interface Place:
public interface Place
{
int distance(Place other);
}
But when I try to implement the interface and compile the following code, a “cannot find symbol – variable xcor” error returns.
public class Point implements Place
{
private double xcor, ycor;
public Point (double myX, double myY)
{
xcor = myX;
ycor = myY;
}
public int distance(Place other)
{
double a = Math.sqrt( (other.xcor - xcor) * (other.xcor - xcor) + (other.ycor - ycor) * (other.ycor -ycor) ) + 0.5;
return (int)a;
}
}
Any ideas for what I might be doing wrong? Does it have something to do with the scope of the fields?
The interface
Placehas no memberxcor. Add a methoddouble getXcor()to your interface and implement it in your class. The same applies toycor. Then you can use these getters in your implementation of thedistancemethod.