Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create an abstract Shape class with three abstract methods: area(), perimeter(), and get Shape().getShape() will return a String that represents a particular shape. (For instance,

image text in transcribed
Create an abstract Shape class with three abstract methods: area(), perimeter(), and get Shape().getShape() will return a String that represents a particular shape. (For instance, getShape() for a Circle should return "circle"). Add a static attribute shapeCount that is incremented every time a new shape is created (where you add a method for incrementing shapeCount is up to you, but the attribute should be present in Shape). Now create three subclasses of Shape: Circle, Triangle, and Rectangle. Also create a Square subclass of Rectangle. The Rectangle and Square classes from previous assignments can be used with some minor edits. Note: to calculate the area of Triangle using three side lengths, use Heron's formula: check out http://www.mathopenref.com/heronsformula.html and the animation there to get the formula and check your results. Make a separate class, ShapeTester to test the functionality of the above classes. Make a Shape ArrayList that contains at least one of each individual shape. Notice that we cannot construct a Shape object since it is an abstract class, but we can create an ArrayList of shapes. Loop through the ArrayList and print out each shape's type using getShape (). Then print only circles and their positions in the array. Then output how many shapes were created using shapeCount field

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions