Consider the Triangle class below Note that it stores the th
Consider the Triangle class below. Note that it stores the three corners of a triangle as three Point objects. Complete the logic inside the getPerimeter method. You can use the distanceTo method that you added to the Point class in the last question.
public class Triangle {
private Point c1;
private Point c2;
private Point c3;
public Triangle(Point c1, Point c2, Point c3) {
this.c1 = c1;
this.c2 = c2;
this.c3 = c3;
}
public double getPerimeter() {
// Your code here
}
}
Solution
Triangle.java
public class Triangle {
private Point c1;
private Point c2;
private Point c3;
public Triangle(Point c1, Point c2, Point c3) {
this.c1 = c1;
this.c2 = c2;
this.c3 = c3;
}
public double getPerimeter() {
// Your code here
double perimeter=0;
double side1=distanceTo(c2, c1);
double side2=distanceTo(c3, c2);
double side3=distanceTo(c3, c1);
perimeter = side1 + side2 + side3;
return perimeter;
}
public double distanceTo(Point p1, Point p2){
return (Math.sqrt(Math.pow(p1.getX() - p2.getX(), 2)+(Math.pow(p1.getY() - p2.getY(), 2))));
}
}

