The following is the definition of an interface called GeometricObject : Any cla
ID: 3775280 • Letter: T
Question
The following is the definition of an interface called GeometricObject:
Any class that implements the GeometricObject interface must include an implementation of its GetArea() and GetPerimeter() methods for that type of object. Complete the following class named Hexagon that implements GeometricObject. Complete the class by filling in the code that goes where the "// Implement it" comments are found. Assume that all sides of the hexagon are of equal size. And also, the formula for the area of a hexagon is given by the following:
area 1.5 V3 side sideExplanation / Answer
using System.IO;
using System;
interface GeometricObject
{
// abstract method for getting the area of the object
double GetArea();
// abstract method for getting the perimeter of the object
double GetPerimeter();
}
public class Hexagon : GeometricObject
{
private double side; // just a variable, there are no properties
/* Constructor of the Hexagon class */
public Hexagon(double hexSide) {
// Implement it
side = hexSide;
}
/* Implements the abstract method getArea */
public double GetArea() {
// Implement it
return 1.5 * Math.Sqrt(3) * side * side;
}
/* Implements the abstract method getPerimeter */
public double GetPerimeter() {
// Implement it
return 6 * side;
}
/* Returns a string representation of the Hexagon object */
public override string ToString() {
// Implement it by returning a string that shows the length
// of the side, along with the area and the perimeter,
// and put each value on a separate line with an
// appropriate label in front of each value, and show
// only 2 places after the decimal
return "Length is: "+side+" Area:"+Math.Round(GetArea(),2)+" Perimeter:"+ Math.Round(GetPerimeter(),2);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.