015-004-003
Dynamic Array: Shape Area Calculation
Medium
Problem Description
Dynamic array: Shape Area Calculation
In this problem, you will create a program that stores Circle and Rectangle objects in a parent class Shape array, calculates each shape's area, and displays the result to standard output.
Learning Objective: Store and process multiple subclass objects in parent class array
Implement Circle and Rectangle subclasses that extend the Shape class, and use polymorphism to calculate the area of each shape in a single loop.
Input
Line 1: Number of shapes n
Following lines: Shape type and dimensions
- circle [radius]
- rectangle [width] [height]
Output
Area of each shape (2 decimal places)
Area 1: [area]
Area 2: [area]
...
```java
## Example
Input:
```java
2
circle 5
rectangle 4 3
```java
Output:
```java
Area 1: 78.54
Area 2: 12.00
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up