-
Notifications
You must be signed in to change notification settings - Fork 0
/
Point.java
71 lines (55 loc) · 1.53 KB
/
Point.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
public class Point {
// need private variables x and y
private int x;
private int y;
private static int numPoints = 0;
// need constructor(s) 0 argument, 2 arguments
public Point() {
x = 0;
y = 0;
numPoints ++;
}
public Point(int x, int y){
this.x = x;
this.y = y;
numPoints ++;
}
// need setter methods
public void setX(int xValue) {
x = xValue;
}
public void setY(int yValue) {
y = yValue;
}
// need getter methods
public int getX() {
return x;
}
public int getY() {
return y;
}
// need translation methods
public void dx(int xValue) {
x += xValue;
}
public void dy(int yValue) {
y += yValue;
}
// need distanceTo() method
public double distanceTo(Point other) {
int xDiff = x - other.getX();
int yDiff = y - other.getY();
return Math.sqrt(Math.pow(xDiff, 2) + Math.pow(yDiff, 2));
}
// need toString() method
public String toString(){
return "(" + x + ", " + y + ")";
}
// need a class variable to keep track total points (put it on top)
// need to class method to return total points (put it just below constructors)
public static int getTotalPoints() {
return numPoints;
}
// need a quadrant() method that return which quadrant the point is located 1, 2, 3, or 4
// need a getAreaUnderCurve() method to return the area underneeth the curver
}