forked from java-tester-x/JavaExercises4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyTriangle.java
More file actions
50 lines (42 loc) · 1.22 KB
/
MyTriangle.java
File metadata and controls
50 lines (42 loc) · 1.22 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
package src;
public class MyTriangle {
private MyPoint v1;
private MyPoint v2;
private MyPoint v3;
public MyTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
this.v1 = new MyPoint(x1, y1);
this.v2 = new MyPoint(x2, y2);
this.v3 = new MyPoint(x3, y3);
}
public MyTriangle(MyPoint v1, MyPoint v2, MyPoint v3) {
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
}
public double getPerimeter() {
return v1.distance(v2) + v1.distance(v3) + v2.distance(v3);
}
/**
* Prints "equilateral" if all the three sides are equal,
* "isosceles" if any two of the three sides are equal,
* or "scalene" if the three sides are different.
*
* @return [description]
*/
public String printType()
{
double d1 = v1.distance(v2);
double d2 = v1.distance(v3);
double d3 = v2.distance(v3);
if (d1 == d2 && d2 == d3) {
return "equilateral";
}
else if (d1 == d2 || d1 == d3 || d2 == d3) {
return "isosceles";
}
return "scalene";
}
public String toString() {
return "Triangle @ "+ v1 +", "+ v2 +", "+ v3;
}
}