beyondgrader.com Logo
DemoBrowseAboutTeamLogin

Pentagon Shape

Geoffrey Challen // 2021.10.0

Create and complete the implementation of the Pentagon class. Your class should be public, inherit from the Shape class, and provide the following methods:

  1. Primary constructor that takes a Double parameter. Creates a new Pentagon with the passed side length. If the passed length is less than or equal to 0, throw an IllegalArgumentException. You should call the Shape constructor and pass it the String "pentagon" to identify the type of this shape.
  2. Public instance method area that takes no arguments and returns a double. Return the area of this shape, given only the side length, which you can find here: https://www.cuemath.com/measurement/area-of-pentagon/. You will need to use sqrt or Kotlin's built-in sqrt to solve this problem.
  3. Override fun equals(other: Any?): Boolean. Return true if other is a Pentagon with the same side length, and false otherwise. Note that other may be null or not a Pentagon.

Finally, note that your class should not expose any of its internal state publicly.