Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following abstract class. Write a (concrete) subclass of Shape call

ID: 3858217 • Letter: C

Question

Consider the following abstract class. Write a (concrete) subclass of Shape called Hexagon. A (regular) hexagon needs a variable for its side length. Add a two-argument constructor accepting a center and the side length, an accessor for the side length, and an implementation of the area method. The area of a regular hexagon is 3 squareroot 3/2 s^2 You may use the approximation squareroot 3 = 1.73 in your implementation. abstract public class Shape { private Point center: public Shape (Point center) { this. center = center: } public Point getCenter() { return center: } abstract public double area(): }

Explanation / Answer

abstract public class Shape{

private Point center;

public Shape(Point center)

{

this.center = center;

}

public Point getCenter()

{

return center;

}

abstract public double area(); // area is an abstract method of class Shape

}

// Hexagon is a sub-class which extends Abstract class Shape

public class Hexagon extends Shape{

private double side; // side is a member of Hexagon class

public Hexagon(Point center, double side){

super(center); // calling super to call the constructor of base class Shape and passing center to it

this.side = side; // initialising side member of Hexagon class

}

//override area for Hexagon

public double area(){

return (((3*1.73)/2)*(side * side));

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote