Problem
You are given the following interface (language-agnostic):
interface Shape {
double area();
double perimeter();
}
Design and implement concrete classes for common shapes (at minimum):
-
Circle(radius)
-
Rectangle(width, height)
Optionally add one more shape (e.g., Triangle(a,b,c) or Square(side)).
Requirements
-
Use OOP best practices (encapsulation, clear naming, polymorphism).
-
Validate inputs (e.g., non-negative dimensions; for triangle, triangle inequality).
-
Make objects safe to use (e.g., immutable fields if possible).
-
Provide a small example showing how a caller can compute total area/perimeter of a list of
Shape
objects.
What to submit
-
Class definitions + brief demonstration code (no need for UI).