016-003-004

Polymorphism with Abstract Classes: Shape Calculator System

Hard

Problem Description

polymorphism with Abstract Classes: Shape Calculator System

In this problem, you will create a program that implements Circle and Triangle classes extending abstract class Shape, stores multiple shapes in a Shape array, calculates each area polymorphically, and displays the individual and total areas to standard output.

Learning Objective: Understand how to handle different shapes uniformly using polymorphism with abstract classes

Overview

Create Circle and Triangle extending abstract Shape class, store in array, and calculate areas polymorphically.

Specifications

  • Shape (abstract): abstract double getArea() and String describe()
  • Circle: Calculate area from radius (PI * r * r)
  • Triangle: Calculate area from base and height (base * height / 2)
  • Manage multiple shapes in Shape array and process with loop

Input

Shape type and parameters are provided

Output Format

Circle: area = 78.54
Triangle: area = 6.00
Total: 84.54

Test Cases

※ Output examples follow programming industry standards

Input:
2
Circle 5.0
Triangle 3.0 4.0
Expected Output:
Circle: area =78.54
Triangle: area =6.00
Total:84.54
Input:
3
Circle 2.0
Circle 3.0
Triangle 5.0 2.0
Expected Output:
Circle: area =12.57
Circle: area =28.27
Triangle: area =5.00
Total:45.84
Input:
0
C
T
Expected Output:
Total:0.00
Input:
2
Circle 5.0
Triangle 3.0 4.0
Expected Output:
Circle: area =78.54
Triangle: area =6.00
Total:84.54
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
Shape.java🔒
Circle.java🔒
Triangle.java🔒
Main.java🔒
4/6 ファイル215B
⚠️警告
  • No main method found
import java.util.Scanner;

abstract class Shape {
}
0 B / 5 MB

You have 3 free executions remaining