Can someone please enlighten me as to what I am doing wrong? I have the errors listed below the code. I am just getting my feet wet with Java so, please be nice in your response.
//The Point class definition
public class Point
{
private int x;
private int y;
// Constructors
public Point()
{
x = 0;
y = 0;
}
public Point(int newX, int newY)
{
x = newX;
y = newY;
}
// Getters and Setters
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public void setX(int newX)
{
x = newX;
}
public void setY(int newY)
{
y = newY;
}
public double distance(Point another) //takes one parameter of Point type and returns a double
{
double xDiff = x - another.x;
double yDiff = y - another.y;
return Math.sqrt(xDiff*xDiff + yDiff*yDiff);
}
public void translate(int dx, int dy)
//takes two int parameters for values used to translate,returns a new point with a new location (do not update current location) point.
{
x = x + dx;
y = y + dy;
}
public void setXY(int newX, int newY) //updates the location of the point all at one time.
{
x = newX;
y = newY;
}
public String toString()
{
return "(" + x + "," + y + ")";
}
}
Error when I run the driver:
PointDriver.java:24: error: method distance in class Point cannot
be applied to given types;
pt3 = pt2.distance(3, -10);
^ required: Point found: int,int reason: actual and formal argument lists differ in length
PointDriver.java:31: error: method distance in class Point cannot be
applied to given types;
pt1 = pt1.distance(4, -2);
^ required: Point
PointDriver
maybe showing that code would be beneficial? Were you supposed to define a methodpublic double distance( int x, int y ){ }
?distance
in classPoint
cannot be applied to given types. ... required: Point found: int,int" It's saying you calleddistance(x, y)
where x and y are ints. But that's not how you declared it. You declared it to take one Point.