014-005-002

Method Overriding: Shape Area Calculator

Easy

Problem Description

Method Overriding: Shape Area Calculator

In this problem, you will create a program that overrides the getArea() method in Circle and Rectangle subclasses of Shape to calculate each shape's area using values read from standard input and display the results.

Learning Objective: Override methods with return values

Create a Shape class representing shapes and Circle/Rectangle classes inheriting from it. Override the getArea() method to implement each shape's area calculation formula.

Input

radius (double)
width (double)
height (double)

Output

Circle area: <area (2 decimal places)>
Rectangle area: <area (2 decimal places)>

Examples

Example 1: radius=5, width=4, height=6

Input:

5.0
4.0
6.0

Output:

Circle area: 78.54
Rectangle area: 24.00

Example 2: radius=3, width=5, height=8

Input:

3.0
5.0
8.0

Output:

Circle area: 28.27
Rectangle area: 40.00

Formulas

  • Circle area: π × radius² (use Math.PI)
  • Rectangle area: width × height

Test Cases

※ Output examples follow programming industry standards

Normal case
Input:
7.0
3.0
5.0
Expected Output:
Circle area: 153.94
Rectangle area: 15.00
Normal case
Input:
2.0
6.0
4.0
Expected Output:
Circle area: 12.57
Rectangle area: 24.00

Your Solution

Current Mode: My Code
Shape.java🔒
Circle.java🔒
Rectangle.java🔒
Solution.java🔒
4/6 ファイル540B
public class Shape {
}
0 B / 5 MB

You have 10 free executions remaining