Submit Hexagon.java to model the concept of a hexagon, that meets the following
ID: 3725053 • Letter: S
Question
Submit Hexagon.java to model the concept of a hexagon, that meets the following specifications:
(there should be no need for static anything in the Class)
1. Two (and only two) private fields:
private Point center; // required to be center of the hexagon
private double side; // the length of one side (all six are same)
2. With two constructors:
Default constructor (set all field data to zeroes)
public Hexagon(Point c, double s) // use Point from java awt
3. The usual accessors and mutators:
public Point getCenter();
public double getSide();
public void setCenter(Point c);
public void setSide(double r);
4. Create a couple more useful methods:
public double area(); // returns area (Google has formula)
For example:
Submit Hexagon.java to model the concept of a hexagon, that meets the following specifications: there should be no need for static anything in the Class) 1. Two (and only two) private fields: private Point center; required to be center of the hexagon private double side; /the length of one side (all six are same) 2. With two constructors: Default constructor (set all field data to zeroes) public Hexagon(Point c, double s)// use Point from java awt 3. The usual accessors and mutators: public Point getCenter); public double getSide; public void setCenter(Point c) public void setSide(double r); 4.Create a couple more useful methods: public double area:/ returns area (Google has formula) public double perimeter0:I/ return perimeter (very simple math)Explanation / Answer
public class Hexagon { private Point point; private double side; public Hexagon() { this.point = new Point(0, 0); this.side = 0; } public Hexagon(Point point, double side) { this.point = point; this.side = side; } public Point getPoint() { return point; } public void setPoint(Point point) { this.point = point; } public double getSide() { return side; } public void setSide(double side) { this.side = side; } public double area() { return Math.sqrt(3)*1.5*side*side; } public double perimeter() { return 6*side; } }