Question: 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,

 Create an abstract Shape class with three abstract methods: area(), perimeter(),

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

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!