Design a class named triangle that extends geometricobject


The following diagram shows the abstract class GeometricObject.
public abstract class GeometricObject {
private String color = "white";
private boolean filled;
/** Return color */
public String getColor() {
return color;
}
/** Set a new color */
public void setColor(String color) {
this.color = color;
}
/** Return filled. Since filled is boolean,
so, the get method name is isFilled */
public boolean isFilled() {
return filled;
}
/** Set a new filled */
public void setFilled(boolean filled) {
this.filled = filled;
}
/** Return a string representation of this object */
public String toString() {
return "\ncolor: " + color + " and filled: " + filled;
}
/** Abstract method getPerimeter */
public abstract double getPerimeter();
}

(a) Design a class named Triangle that extends GeometricObject. The class contains three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle. Implement the getPerimeter() that returns the perimeter of this triangle

(b) Re-design the class Triangle that also implements Comparable. The triangles are compared in terms of their perimeters.

(c)

Design a new class named Polygon that extends GeometricObject and implements Comparable. The number of sides in polygons varies, you cannot use a certain number of data fields for sides of a polygon. For example a triangle is seen as a polygon with three sides and a rectangle is a polygon of four sides. Please use a List of Double values to denote the length of each side of a polygon. Implement the getPerimeter() that returns the perimeter of this triangle

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Design a class named triangle that extends geometricobject
Reference No:- TGS0762522

Expected delivery within 24 Hours