Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems analysis and design

Authors: kenneth e. kendall, julie e. kendall

8th Edition

135094909, 013608916X, 9780135094907, 978-0136089162

More Books

Students also viewed these Programming questions

Question

Find the x- and y-coordinates of each labeled point. + D' S--3-2-

Answered: 1 week ago

Question

Question 14: Good governance - has a value in the market place?

Answered: 1 week ago

Question

What is the purpose of using a mnemonic code for data?

Answered: 1 week ago