-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint.java
96 lines (89 loc) · 1.45 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package Abstract;
public class Point {
private double price;
private int quant;
private final double TOLORANCE = 0.01;
/**
* default construction of a point
*/
public Point()
{
price = 0.0;
quant = 0;
}
/**
* point constructed with parameters to create a specific point
* @param q
* @param p
*/
public Point(int q, double p)
{
price = p;
quant = q;
}
public String toString()
{
String s = "("+this.getQuant()+","+this.getPrice()+")";
return s;
}
/**
* get quantity
* @return
*/
public int getQuant()
{
return quant;
}
/**
* get Price
* @return
*/
public double getPrice()
{
return price;
}
/**
* set price
* @param p
*/
public void setPrice(double p)
{
price = p;
}
/**
* set quantity
* @param q
*/
public void setQuant(int q)
{
quant = q;
}
/**
* checks if an object is a point and if so directs it to equals(point a)
* Overrides Object.equals()
*/
public boolean equals(Object o)
{
if(o instanceof Point)
{
Point p = (Point) o;
return equals(p);
}
return false;
}
/**
* compares two points and returns a boolean regarding their relation and accounts for a rounding tolerance
* true = equal, false != equal
* overloads Object.equals()
* @param a
* @return
*/
public boolean equals(Point a)
{
if ((Math.abs(this.getPrice() - a.getPrice()) <= TOLORANCE) && (this.getQuant() == a.getQuant()))
{
return true;
}
return false;
}
}