@Test public void whenAddThreeCorrectPointsResultFifty() { Point a = new Point(0d,0d); Point b = new Point(10d,0d); Point c = new Point(0d,10d); Triangle tri = new Triangle(a,b,c); assertThat(tri.area(), is(50d)); }
public double area() { double result = 0; double sideAB = this.a.distanceTo(b); double sideBC = this.b.distanceTo(c); double sideAC = this.a.distanceTo(c); double halfP = (sideAB + sideAC + sideBC)/2.0d; if ((sideAB < (sideBC + sideAC)) && (sideBC < (sideAC + sideAB)) && (sideAC < (sideBC + sideAC))) { result = Math.sqrt(halfP * (halfP - sideAB) * (halfP - sideAC) * (halfP - sideBC)); } else { System.out.println("Треугольника не существует"); } return result; }
Triangle { public double area() { double result = 0; double sideAB = this.a.distanceTo(b); double sideBC = this.b.distanceTo(c); double sideAC = this.a.distanceTo(c); double halfP = (sideAB + sideAC + sideBC)/2.0d; if ((sideAB < (sideBC + sideAC)) && (sideBC < (sideAC + sideAB)) && (sideAC < (sideBC + sideAC))) { result = Math.sqrt(halfP * (halfP - sideAB) * (halfP - sideAC) * (halfP - sideBC)); } else { System.out.println("Треугольника не существует"); } return result; } }
Triangle { public double area() { double result = 0; double sideAB = this.a.distanceTo(b); double sideBC = this.b.distanceTo(c); double sideAC = this.a.distanceTo(c); double halfP = (sideAB + sideAC + sideBC)/2.0d; if ((sideAB < (sideBC + sideAC)) && (sideBC < (sideAC + sideAB)) && (sideAC < (sideBC + sideAC))) { result = Math.sqrt(halfP * (halfP - sideAB) * (halfP - sideAC) * (halfP - sideBC)); } else { System.out.println("Треугольника не существует"); } return result; } Triangle(Point a, Point b, Point c); }
Triangle { public double area() { double result = 0; double sideAB = this.a.distanceTo(b); double sideBC = this.b.distanceTo(c); double sideAC = this.a.distanceTo(c); double halfP = (sideAB + sideAC + sideBC)/2.0d; if ((sideAB < (sideBC + sideAC)) && (sideBC < (sideAC + sideAB)) && (sideAC < (sideBC + sideAC))) { result = Math.sqrt(halfP * (halfP - sideAB) * (halfP - sideAC) * (halfP - sideBC)); } else { System.out.println("Треугольника не существует"); } return result; } Triangle(Point a, Point b, Point c); double area(); }
Triangle { public double area() { double result = 0; double sideAB = this.a.distanceTo(b); double sideBC = this.b.distanceTo(c); double sideAC = this.a.distanceTo(c); double halfP = (sideAB + sideAC + sideBC)/2.0d; if ((sideAB < (sideBC + sideAC)) && (sideBC < (sideAC + sideAB)) && (sideAC < (sideBC + sideAC))) { result = Math.sqrt(halfP * (halfP - sideAB) * (halfP - sideAC) * (halfP - sideBC)); } else { System.out.println("Треугольника не существует"); } return result; } Triangle(Point a, Point b, Point c); double area(); public Point a; public Point b; public Point c; }