Interface for geometric shapes
Go
Medium
interfaces
Task «Interface for geometric shapes»
Implement the Shape interface, which contains the Area() float64 method. Create the Circle and Rectangle structures that implement this interface. For a circle, the area is calculated as π * r^2, for a rectangle — a * b. Then write a function PrintArea(s Shape) that prints the area of the shape with an accuracy of two decimal places. Input data: shape type (1 — circle, 2 — rectangle) and the corresponding parameters (radius for a circle, sides a and b for a rectangle). Output the area of the shape.
Input Format
First line: an integer t (1 ≤ t ≤ 100) — the number of shapes. For each shape: the first line is an integer type (1 or 2). If type=1, the next line contains one real number — the radius. If type=2, the next line contains two real numbers — sides a and b.
Output Format
For each shape, output its area with an accuracy of two decimal places, each on a new line.
Examples
Example 1
INPUT
1
0
OUTPUT
1
Example 2
INPUT
4
ADD Task A 1
ADD Task B 4
COMPLETE Task C
PENDING
OUTPUT
Task not found
Task B, Task A
main.go