Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions

Question

What does this public think about this issue?

Answered: 1 week ago

Question

What benefits can you offer this public?

Answered: 1 week ago

Question

How free does this public see itself to act on this issue?

Answered: 1 week ago