-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.java
More file actions
62 lines (55 loc) · 1.67 KB
/
Point.java
File metadata and controls
62 lines (55 loc) · 1.67 KB
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
/**************************************************************/
/* Josh Lindoo
/* Login ID: lind6441
/* CS-203, Summer 2013
/* Programming Assignment 2
/* Point class: object used to represent a point in a 2d plane
/**************************************************************/
public class Point implements Comparable<Point>{
//fields
private double xCoord = 0; //point's x value
private double yCoord = 0; //point's y value
//constructor
public Point(double xCoord, double yCoord) {
this.xCoord = xCoord;
this.yCoord = yCoord;
}
/**************************************************************/
/* Method: getX and getY
/* Purpose: Accessor methods
/* Parameters:
/* none
/* Returns: double -- the x or y value
/**************************************************************/
public double getX() {
return xCoord;
}
public double getY() {
return yCoord;
}
/**************************************************************/
/* Method: compareTo
/* Purpose: Compare points by x value and then res. ties by y val
/* Parameters:
/* String[] args: filename or -debug filename
/* Returns: void
/**************************************************************/
public int compareTo(Point point) {
if(xCoord - point.getX() > 0) return 1;
else if(xCoord - point.getX() == 0) {
if(yCoord - point.getY() > 0) return 1;
else return -1;
}
else return -1;
}
/**************************************************************/
/* Method: toString
/* Purpose: Print point info
/* Parameters:
/* none
/* Returns: void
/**************************************************************/
public String toString() {
return "(" + xCoord + "," + yCoord + ")";
}
}