Design a general class GeometricObject can be used to model all geometric
Design a general class GeometricObject can be used to model all geometric
objects. This class contains the properties color and filled and their appropriate get and set methods. Assume that this class also contains toString() methods. The toString() method returns a string representation of the object.
Define the Triangle, Circle, and Rectangle classes that extend the GeometricObject class.
-The Triangle class inherits all accessible data fields and methods from the GeometricObject class.In addition, it has three double data fields named side1, side2, and side3 with default values 2.0 to denote three sides of the triangle. Also contains:
-A no-arg constructor that creates a default triangle.
-A constructor that creates a triangle with the specified side1, side2, and side3.
-The accessor methods for all three data fields.
-A method named getArea() that returns the area of this triangle.
-A method named getPerimeter() that returns the perimeter of this triangle.
-A method named toString() that returns a string description for the triangle implemented as follows:return “Triangle: side1 = ” + side1 + ” side2 = ” + side2 + ” side3 = ” + side3;
-The Circle class inherits all accessible data fields and methods from the GeometricObject class. In addition, it has a new data field, radius, and its associated get and set methods. The Circle class also contains the getArea(), getPerimeter(), and getDiameter() methods for returning the area, perimeter, and diameter of the circle.
-The Rectangle class inherits all accessible data fields and methods from the GeometricObject class. In addition, it has the data fields width and height and their associated get and set methods. It also contains the getArea() and getPerimeter() methods for returning the area and perimeter of the rectangle.
Design a Test class which creates objects of Triangle, Circle and Rectangle and invokes the methods on these objects. The toString() method is inherited from the GeometricObject class and is invoked from a Triangle object, Circle object and a Rectangle object.
Note
In Java terminology, a class C1 extended from another class C2 is called a subclass, and C2 is called a superclass. A superclass is also referred to as a parent class or a base class, and a subclass as a child class, an extended class, or a derived class. A subclass inherits accessible data fields and methods from its superclass and may also add new data fields and methods.
The formula to compute the area of a triangle is:
s = (side1 + side2 + side3)/2;
area = SQRT (s(s – side1)(s – side2)(s – side3))
SQRT is a function that returns the square root of parameter.