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
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...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started