Question
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
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.
Please take care at the input data. The input data have to be eligible (numeric values) and you have to verify the existence of objects ( for example : the width and height of rectangle have to be positive numbers).
If the input data is not correct , you have to ask the user to enter again the data
1. all sides have to be positive
2. for triangle you need to verify the Triangle ABC Inequality Theorem yields three inequalities:
AB + BC > CA
BC + CA > AB
CA + AB > BC
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started