Question
Define an interface named Shape with a single method named area that calculates the area of the geometric shape. public double area(); Next, define a
Define an interface named Shape with a single method named area that calculates the area of the geometric shape. public double area(); Next, define a class named Circle that implements Shape. The Circle class should have an instance variable for the radius, a constructor that sets the radius, accessor/mutator methods for the radius, and an implementation of the area method. Define another class named Rectangle that implements Shape. The Rectangle class should have instance variables for the height and width, a constructor that sets the height and width, accessor and mutator methods for the height and width, and an implementation of the area method. Define a third class named Triangle that implements Shape. The Triangle class should have instance variables for the height and width, a constructor that sets the height and width, accessor and mutator methods for the height and width, and an implementation of the area method. To test the interface Shape and the classes Circle, Rectangle, and Triangle, create an array of nine objects of type Shape. Then create nine objects (3 of each class that implements the interface Shape) and store them in the array. Finally, print the content of the array to display the area of the nine objects.
In java please
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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