Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please please help Part C : Create an ABSTRACT class, called Simple_Polygon (which implements our ' Polygon ' interface) with the following specifications:

Please please help

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".
    • 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).
    • Important: If argument is less than 3, throw a 'IllegalArgumentException'.
    • Note: No other constructors should be present (even the default constructor).
  • Implement the [inherited] "getNumberOfSides" function.
    • Hint: There's a [direct] correlation between the number of edges and points.
  • 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).
    • Important: This should go without saying, but make sure that this function works no matter how many sides / vertices there are.
    • Note: Do NOT worry about having to deal with any approximation errors that may come about when using the 'equals' and/or 'not equals' operator with 'double' operands. IE. (1.0 == 1.0) versus (1.0 == 1.0000000001)
    • Tip: Invoke our class 'Point's distance function with specific vertices as arguments.
      • Don't forget (as stated earlier), you can assume that said polygon's points are stored / organized in [clockwise] order.

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).
    • Hint: Don't forget to invoke the superclass' constructor (using the 'super' keyword and an appropriate value).
    • Note: You can assume that [all] arguments will be "non-null" values.
  • Implement the [inherited] "getPerimeter" function.
    • As the name implies, this function should return the total [sum] length between this class' [3] vertices ("A => B", "B => C" and "C => A").
      • Tip: Again, invoke class 'Point's distance function.
  • Implement the [inherited] "getArea" function.
    • 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).
    • Hint: Don't forget to invoke the superclass' constructor (using the 'super' keyword and an appropriate value).
    • Note: You can assume that [all] arguments will be "non-null" values.
  • Implement the [inherited] "getPerimeter" function.
    • 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").
      • Tip: Again, invoke class 'Point's distance function.
  • Implement the [inherited] "getArea" function.
    • As the name implies, this function should return the area that this class' vertices surround. This can be easily found using the following equation:
      • 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

More Books

Students also viewed these Databases questions