Basic Polymorphism: Shape Area
Problem Description
Basic polymorphism: Shape Area
In this problem, you will create a program that defines Rectangle and Circle classes inheriting from Shape, accepts a shape type and dimensions as input, and uses polymorphism to call the same calcArea method on each shape object to display the corresponding area to standard output.
Learning Objective: Understand using common interface through polymorphism
Create Rectangle and Circle classes inheriting from Shape, and store each object in a Shape-typed variable to invoke the same calcArea method, achieving different area calculations depending on the concrete shape type.
Input
Line 1: Shape type (rect or circle)
Line 2: For rect: width and height (space separated), for circle: radius
Output
Type: [type]
Area: [area (2 decimal places)]
Example
Input:
rect
4 5
Output:
Type: Rectangle
Area: 20.00
Test Cases
※ Output examples follow programming industry standards
circle 7
Type: Circle Area:153.94
circle 3
Type: Circle Area:28.27
Your Solution
- No main method found
You have 10 free executions remaining
