Question: Question Goal: Apply ideas about inheritance with Abstract classes Assignment: Imagine that you are a mathematician that is creating a program to automatically generate shape

Question
Goal: Apply ideas about inheritance with Abstract classes
Assignment: Imagine that you are a mathematician that is creating a program to automatically generate shape objects. The concept of a shape means nothing on its own but begins to take shape ;) when you define its boundaries.
The Abstract class Shape has already been created for you. Shape defines the abstract method calculateArea and the concrete method displayShape which prints "This is a shape.".
Create two classes, Circle and Rectangle that meet the following requirements:
They can be instantiated
They have constructor methods that define the minimum properties for calculating the shape's area (e.g. you only need a circle's radius to calculate its area). These should be integers.
They redefine the calculateArea method to calculate and return that shape's area.
They override the displayShape method to display "This is a ".
// Abstract class Shape, serving as a blueprint for various shapes
abstract class Shape {
// Abstract method to calculate the area, must be implemented by subclasses
public abstract double calculateArea();
// A concrete method to display the type of shape
public void displayShape(){
System.out.println("This is a shape.");
}
}
// Write your code here. Please explain as well. Thank you!

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!