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;
}
}
|