Question: Shape.java Abstract class called Shape declare public member variables width of type double height of type double declare and implement a method called setSize 2

Shape.java

Abstract class called Shape

declare public member variables

width of type double

height of type double

declare and implement a method called setSize

2 parameters: width, height of type double

This method sets/initializes the member variables width and height

declare an abstract method called getArea

The return type of this method should be double

No parameters

--------------------------------------

Rectangle.java

Rectangle class inherits members of Shape class

This class has only one method called getArea

getArea method should return the area of a rectangle

---------------------

Triangle.java

Triangle class inherits members of Shape class

This class has only one method called getArea

getArea method should return the area of a triangle

-------------------------------

Driver.java

main method

Declare/init a new object of type Triangle

Declare/init a new object of type Rectangle

Declare an object of type Shape and assign it to the the triangle object

Using the Shape object, call setSize method providing arguments width/height

Reassign the shape object to the rectangle object

Using the Shape object, call setSize method providing arguments width/height

Using the triangle object, print out the area of the triangle by calling getArea()

Using the rectangle object, print out the area of the rectangle by calling getArea()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!