Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gd;
- /**
- * A specific shape: A triangle.
- * This triangle inherits from shape
- * @author hypesystem
- * @email [email protected]
- */
- public class Triangle extends Shape {
- private double a, b, c;
- /**
- * Creates a triangle witout a coordinate argument (sets coordinates to 0,0)
- * @param a side of triangle
- * @param b side of triangle
- * @param c side of triangle
- */
- public Triangle(double a, double b, double c) {
- super(new Coordinate(0,0));
- setAttr(a,b,c);
- }
- /**
- * Creates a triangle with a coordinate argument.
- * @param a side of triangle
- * @param b side of triangle
- * @param c side of triangle
- * @param coordinates coordinates of triangle
- */
- public Triangle(double a, double b, double c, Coordinate coordinates) {
- super(coordinates);
- setAttr(a,b,c);
- }
- /**
- * Sets the attributes of the Triangle. Called from constructors (hence
- * private)
- * @param a side of triangle
- * @param b side of triangle
- * @param c side of triangle
- */
- private void setAttr(double a, double b, double c) {
- this.a = a;
- this.b = b;
- this.c = c;
- }
- /**
- * Calculates and returns the circumference of the triangle. Inherited from
- * Shape.
- * @return circumference of triangle
- */
- @Override
- public double circumference() {
- return a + b + c;
- }
- /**
- * Calculates and returns the area of the triangle. Inherited from Shape.
- * @return area of triangle
- */
- @Override
- public double area() {
- double s = (a + b + c) / 2;
- return Math.sqrt(s * (s - a) * (s - b) * (s - c));
- }
- /**
- * Counts the amount of simple shapes in this shape. This is a simple shape.
- * Inherited from Shape.
- * @return 1
- */
- @Override
- public int countSimple() {
- return 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment