Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Create an Interface called Shapes with one method: public int getArea() 2. Create a Rectangle class that implements the Shapes interface. It will have

1. Create an Interface called Shapes with one method:

public int getArea()

2. Create a Rectangle class that implements the Shapes interface.

It will have a data members length and width and area as integers

It will have an argument constructor to pass length and width

It will have getLength()//returns length

It will have getWidth()//returns width

It will have getArea()//will assign area to be length * width then returns area

3. Create a Square class that implements the Shapes Interface

It will have as data members side and area as integers

It will have an argument constructor to pass side

It will have getSide()//returns side

It will have getArea()// assigns area to be side*side and then returns area

4. Create a shapesDemo class

In the main method create 2 objects one for Rectangle r1 and one for Square s1.

For the rectangle pass 10 and 15, and for the square pass 4

Using the getLength() and getWidth() method calls display the dimensions for the Rectangle

Using the showArea() display rectangle's area

Using the getSide() method call display the side of the square

Using the showArea() dispaly the square's area

**Create the showArea definition as a static method that passes the Shapes Inteface

Output is in form

Area: calcualtedArea

AFter finishing the above create similar classes for

Triangle which has base height and area and methods getBase(), getHeight()

and getArea()

int area=(base*height)/2;

return area;

Circle which has radius and area and getRadius() and

getArea()

int area=(int)( 3.14*radius*radius);

return area;

In the main create t1 from Triangle to pass through 10 and 5 and c1 from Circle to pass through 10

Using the getBase() and getHeight() display triangle's base and height

Use show showArea() to display triangle's area

Using the getRadius() display circle's radius

Using the showArea() display circle's area

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

Students also viewed these Databases questions

Question

Let A = {a, b, c, d} and B = {y, z}. Find a) A B. b) B A.

Answered: 1 week ago

Question

7. What qualities do you see as necessary for your line of work?

Answered: 1 week ago