Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please please help!! Part B: Create an interface, called Polygon, with the following specifications: Declare three [public] functions called getNumberOfSides, getPerimeter, and getArea. Part C:
please please help!!
Part B: Create an interface, called "Polygon", with the following specifications:
Declare three [public] functions called "getNumberOfSides", "getPerimeter", and "getArea".
Part C: Create an ABSTRACT class, called "Simple_Polygon" (which implements our 'Polygon' interface) with the following specifications:
A protected attribute that's an array of 'Point's, called "vertices".
o Important: For the following class (and remaining parts), how the elements are organized does matter, HOWEVER, to make things more manageable, you can assume that all of this array's points will [always] be organized in a clockwise manner. For examples:
(0, 1) => (1, 1) => (1, 0) => (0, 0) forms a 'square', where as ...
(0, 1) => (1, 0) => (0, 0) => (1, 1) would form a 'hourglass'.
As seen with the latter example, if lines were drawn between [adjacent] points, then we'd have intersecting edges.
You can assume that said scenarios will NEVER occur.
A constructor, with ONE integer parameter, that'll define the 'vertices' attribute with a new array of 'Point's (where it's size is based on said parameter's value).
o Important: If argument is less than 3, throw a 'IllegalArgumentException'.
Implement the [inherited] "getNumberOfSides" function
Define a [public] function called "isEquilateral" which will return true if all of this polygon's sides are of equal length (otherwise it'll return false).
Note: Do NOT worry about having to deal with any approximation errors
o Tip: Invoke our class 'Point's distance function with specific vertices as arguments.
Part D: Create a class called "Triangle", which extends from our 'Simple_Polygon' class, with the following specifications:
A constructor with THREE parameters that are all of data type 'Point'.
The given values must then be assigned into the 'vertices' array (in order).
o Hint: Don't forget to invoke the superclass' constructor
Implement the [inherited] "getPerimeter" function.
o As the name implies, this function should return the total [sum] length between this class' [3] vertices ("A => B", "B => C" and "C => A
Implement the [inherited] "getArea" function.
o As the name implies, this function should return the area that this class' [3] vertices surround. This can be easily found using the following equation:
Legend:
Vertex 1 = (x1, y1), Vertex 2 = (x2, y2), Vertex 3 = (x3, y3)
Formula:
Absolute value of ((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2)
Part E: Create a class called "Quadrilateral", which extends from our 'Simple_Polygon' class, with the following specifications:
A constructor with FOUR parameters that are all of data type 'Point'.
The given values must then be assigned into the 'vertices' array (in order).
Implement the [inherited] "getPerimeter" function.
o As the name implies, this function should return the total [sum] length between this class' vertices ("A => B", "B => C", "C => D" and "D => A").
Legend:
Vertex 1 = A, Vertex 2 = B, Vertex 3 = C, Vertex 4 = D
Formula:
(Area of Triangle 'ABD') + (Area of Triangle 'BCD')
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