Пример #1
0
 public static void main(String[] args) {
   Triangle t = new Triangle(new Point(1, 2), new Point(3, 4), new Point(1, 3));
   t.printPoints();
   System.out.printf("Umfang: %f\nFläche %f\nBewege um (2|4) ...\n", t.perimeter(), t.area());
   t.move(2, 4);
   t.printPoints();
 }
Пример #2
0
  @Override
  // first, I create object of Triangle, the identical one to our object Triangle2 with the left
  // angle point in (0,0)
  // after it, I move it on with move method of Triangle
  public void move(double dx, double dy) {

    Triangle triangle =
        new Triangle(
            new Point(0, 0), new Point(0, base), new Point(height / Math.tan((angle)), height));

    triangle.move(dx, dy);
    System.out.println("Our triangle's left base angle was in (0,0). Now it's moved");
  }
  private static boolean testTriangle() {
    boolean pass = true;
    int test = 1;
    Triangle tri;
    Point a = new Point(4, 0);
    Point b = new Point(-2, -1);
    Point c = new Point(1, 4);

    System.out.println("Triangle tests...");

    tri = new Triangle(a, b, c, Color.cyan, false);
    pass &= test(approx(tri.getArea(), 13.5, 0.000001), test++);
    pass &= test(tri.getColor().equals(Color.cyan), test++);

    tri.setColor(Color.black);
    pass &= test(tri.getColor().equals(Color.black), test++);
    pass &= test(!tri.getFilled(), test++);

    tri.setFilled(true);
    pass &= test(tri.getFilled(), test++);
    pass &= test(tri.getVertexA().equals(new Point(4, 0)), test++);
    pass &= test(tri.getVertexB().equals(new Point(-2, -1)), test++);
    pass &= test(tri.getVertexC().equals(new Point(1, 4)), test++);

    a = new Point(7, -3);
    tri.setVertexA(a);
    pass &= test(tri.getVertexA().equals(new Point(7, -3)), test++);

    b = new Point(13, 56);
    tri.setVertexB(b);
    pass &= test(tri.getVertexB().equals(new Point(13, 56)), test++);

    c = new Point(-3, 23);
    tri.setVertexC(c);
    pass &= test(tri.getVertexC().equals(new Point(-3, 23)), test++);
    pass &= test(approx(tri.getArea(), 373.0, 0.000001), test++);

    tri.move(new Point(-5, -7));
    pass &= test(tri.getVertexA().equals(new Point(2, -10)), test++);
    pass &= test(tri.getVertexB().equals(new Point(8, 49)), test++);
    pass &= test(tri.getVertexC().equals(new Point(-8, 16)), test++);

    a = new Point(2, -10);
    b = new Point(8, 49);
    c = new Point(-8, 16);

    Triangle tri2 = new Triangle(a, b, c, Color.black, true);
    pass &= test(tri.equals(tri2), test++);

    Triangle tri3 = new Triangle(new Point(3, -9), b, c, Color.black, false);
    pass &= test(!tri2.equals(tri3), test++);

    tri3 = new Triangle(a, new Point(7, 48), c, Color.black, false);
    pass &= test(!tri2.equals(tri3), test++);

    tri3 = new Triangle(a, b, new Point(-7, 17), Color.black, false);
    pass &= test(!tri2.equals(tri3), test++);

    tri3 = new Triangle(a, b, c, Color.red, false);
    pass &= test(!tri2.equals(tri3), test++);

    pass &= test(!tri2.equals(null), test++);
    pass &= test(!tri2.equals(new String("Whatever")), test++);

    return pass;
  }