Create an application named ShapesDemo that creates several objects that descend from an abstract class called GeometricFigure. Each GeometricFigure includes a height, a width, and an area. Provide get and set accessors for each field except area; the area is computed and is read-only. The class includes an abstract method called computeArea( ) that computes the area of the Geometric Figure.

GeometricFigure base class is provided.

abstract class GeometricFigure
{
protected int height;
protected int width;
protected int area;
public GeometricFigure(int h, int w)
{
Height = h;
Width = w;
}
public abstract double ComputeArea();
public int Height
{
get
{
return height;
}
set
{
height = value;
}
}

public int Width
{
get
{
return width;
}
set
{
width = value;
}
}
public int Area
{
get
{
return area;
}
}
}

Create two additional classes:

  • A Rectangle is a GeometricFigure whose area is determined by multiplying width by height. In the Rectangle class, the constructor performs no tasks other than passing out the height and width to the GeometricFigure constructor.Override computeArea( ) in the Rectangle class by multiplying width by height
  • A Triangle is a GeometricFigure whose area is determined by multiplying the width by half the height. In the Triangle class, the constructor performs no tasks other than passing out the height and width to the GeometricFigure constructor. Override computeArea( ) in the Triangle class by multiplying the width by half the height.

In the Main( ) method, implement Rectangle and Triangle objects.

Create an instance of a Rectangle class, that takes height = 10 and width = 5 as input. Display the height, width and the area of the rectangle.

Rectangle rect1 = new Rectangle( 10, 5);

Create another instance of the Triangle class, that takes height = 25 and width = 15 as input. Display the height, width and the area of the Triangle.

Triangle tr1 = new Triangle(25, 15);

Refer to abstract Animal class, inherited Dog and Cat classes, and DemoAnimals program in the textbook included in the section, Creating and Using Abstract Classes.

Sample output:

Area of the rectangle with height = 3 and width = 4 is: 12
Area of the triangle with height = 10 and width = 20 is: 100
Press any key to continue . . .
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.