1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
public class Point {
int x; // Each Point object has
int y; // an int x and y inside.
public void Point(int initX, int initY) { // Constructor
initX = x;
initY = y;
}
public static double distanceFromOrigin() { // Returns this point's
int x; // distance from (0, 0).
int y;
double dist = Math.sqrt(x*x + y*y);
return dist;
}
public void translate(int dx, int dy) { // Shifts this point's x/y
int x = x + dx; // by the given amounts.
int y = y + dy;
}
}
|
The above Point class has 8 errors. Can you find them all?
voidstaticx and yx and y (remove word int)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public class Point {
int x;
int y;
public Point(int initX, int initY) {
x = initX;
y = initY;
}
public double distanceFromOrigin() {
double dist = Math.sqrt(x*x + y*y);
return dist;
}
public void translate(int dx, int dy) {
x = x + dx;
y = y + dy;
}
}
|