Question
This program should be called Hexagons.java For this program, youre required to implement the Hexagons class that describes a regular hexagon. A reg- ular hexagon
This program should be called Hexagons.java
For this program, youre required to implement the Hexagons class that describes a regular hexagon. A reg- ular hexagon is a polygon with 6 sides, where all the sides are of equal length. The class is described as follows:
The class should be in a package called Hex, and should be declared public.
The class has only one data attribute, called sideLength, of type double.
Write accessor and mutator methods for sideLength. Please follow Java naming convention for these methods.
Write a default constructor that sets the value of sideLength to 1.
Write a parametrized constructor that sets sideLength. If the given length is 0 or negative, it shoulde be set to the default length of 1.
Write a method called perimeter that calculates the perimeter of the hexagon. Perimeter of a regular hexagon is 6 * side length.
Write a method called area that calculates the area of the hexagon. The area of a regular hexagon is ((3*sqrt(3))/2)*(side length)^2
Write a method called printHex that prints the side length, perimeter and area of the hexagon.
The main method should be the only static method in the class.
In the main method, accept the number of hexagons N from the user. Then create an array of N objects of the Hexagons class. Read in the side lengths of the N hexagons and use the mutator method to set the values of the side lengths to each of the Hexagons objects. Then, call the printHex method to print the properties of the hexagons, one by one. All values should be rounded to 3 decimal digits.
Sample Run
Enter the number of hexagons : 3
Enter the side lengths of the 3 hexagons: 10
-8
15.92
Hexagon 1
Side Length : 10
Perimenter : 60
Area : 259.81
Hexagon 2 Side Length : 1
Perimenter : 6
Area : 2.60
Hexagon 3 Side Length : 15.92
Perimenter : 95.52
Area : 658.47
3 Compatibility Once your class is compiled into a classfile, I should be able to instantiate (create objects) the class in another program and use the objects. For example, I should be able to compile the Hexagons class inside the Hex directory, and then run the UsesHexagons class from the parent directory. The UsesHexagons class can be found at http://ww2.cs.fsu.edu/~tan/java18/Examples/UsesHexagons.java Generic Guidelines
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