014-005-004

Utilizing Overridden Methods: Diverse Behavior

Hard

Problem Description

Utilizing Overridden Methods: Diverse Behavior

In this problem, you will create a program that overrides the getArea() method of the Shape class in Rectangle and Triangle to calculate each shape's area from dimensions read via standard input.

Learning Objective: Understand how to achieve different behavior with the same method name through overriding

Overview

Create a program that calculates the area of shapes. override the getArea() method of Shape class in Rectangle and Triangle.

Specifications

  • Shape class: getArea() method (returns 0.0)
  • Rectangle class: calculate area with width and height (width * height)
  • Triangle class: calculate area with base and height (base * height / 2)
  • Output each shape's area

Input Format

rectangle width
rectangle height
triangle base
triangle height

Output Format

Rectangle Area: (rectangle area)
Triangle Area: (triangle area)

Sample Input/Output

Input:

4
5
6
5

Output:

Rectangle Area: 20.0
Triangle Area: 15.0

Test Cases

※ Output examples follow programming industry standards

Normal case
Input:
5
6
9
4
Expected Output:
Rectangle Area: 30.0
Triangle Area: 18.0
Normal case
Input:
3
7
8
4
Expected Output:
Rectangle Area: 21.0
Triangle Area: 16.0

Your Solution

Current Mode: My Code
Shape.java🔒
Rectangle.java🔒
Triangle.java🔒
Main.java🔒
4/6 ファイル389B
class Shape {
}
0 B / 5 MB

You have 10 free executions remaining