-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTriangle.java
59 lines (48 loc) · 1.37 KB
/
Triangle.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
public class Triangle extends Shape {
double height, base, orientation;
public Triangle(double b, double h, double o, Point p, String c) throws BadColorException{
super(p, c);
while (o < 0)
o = o + 360;
while (o >= 360)
o = o - 360;
base = Math.abs(b);
height = Math.abs(h);
orientation = o;
}
public Triangle(Triangle t) {
super(t);
height = t.height;
base = t.base;
orientation = t.orientation;
}
public void erase() {
System.out.println(base + " by " + height + " Triangle erased at " + getCenter().toString());
}
public void draw(){
System.out.println(base + " by " + height + " Triangle drawn at " + getCenter().toString());
}
public Point getCenter() {
return super.getCenter();
}
public double getArea() {return base*height/2;}
/*public int compareTo(Object o) {
Triangle t = (Triangle)o;
if(base*height > t.base*t.height) return 1;
if(base*height < t.base*t.height) return -1;
return 0;
//it doesn't matter *what* negative or positive value is returned
//if we're comparing int values here, you can just subtract.
//I didn't change from Rectangle because / 2 doesn't change the comparisons.
}*/
public void rotate(double d) {
orientation += d;
while (orientation < 0)
orientation += 360;
while (orientation >= 360)
orientation -= 360;
}
public Triangle clone() {
return new Triangle(this);
}
}