Question: Using Area_Ext 1. - Extend the class AreaShape to include methods to calculate: - Area of a Rectangle; - Area of a Triangle; - Area

Using Area_Ext

1. - Extend the class AreaShape to include methods to calculate:

- Area of a Rectangle;

- Area of a Triangle;

- Area of the surface of a cylinder



I think I'm on the right track, but I'm honestly not really sure. I would like some clarification.



My code:



class AreaShape

{

double area;


public void square(double x, double y)

{

area = x * y;

System.out.println("The area of a square with the given numbers:"+ area);

}

}


public class Area_Ext extends AreaShape

{

public void circle(double radius)

{

area = 3.14 * radius;

System.out.println("The area of a circle with the given numbers: "+ area);

}

public void rectangle (double area) {

int width=4;

int height=6;

area = width*height;

System.out.println ("The area of a rectangle with the given numbers: "+ area);

}

public void triangle (double area)

{

int base = 15;

int height = 50;

area = (base* height)/2;

System.out.println("The area of a triangle with the given numbers:"+ area);

}

public void cylinder (double area)

{

float r, h, surfacearea;

r = 4;

h = 7;

surfacearea = (22*r*(r+h))/7;

System.out.println("Surface Area of Cylinder with the given numbers is: "+surfacearea);

}



public static void main(String args[])

{

double a = 20.5, b = 10.3;

double radius=15.5;

Area_Ext MyArea = new Area_Ext();

MyArea.square(a, b);

MyArea.circle(radius);

MyArea.rectangle(radius);

MyArea.triangle(radius);

MyArea.cylinder(radius);

}

}

Step by Step Solution

3.38 Rating (145 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To extend the AreaShape class and include methods to calculate the area of a rectangle triangle and the surface area of a cylinder you need to properl... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!