In computational geometry, abstraction allows us to treat distinct shapes as a unified collection of figures. This project implements a Geometry Library foundation using an abstract Figure class. By defining a mandatory area() contract, we ensure that every shape added to the library—whether it is a Square or a Circle—can provide its area on demand. This approach encapsulates the unique mathematical formulas (
- Abstract Logic: Established the
Figureclass as a blueprint for all geometric entities. - Formula Encapsulation: Implemented specific area formulas within
SquareandCircle. - Mathematical Accuracy: Utilized
Math.PIfor precise circular calculations. - Polymorphic Testing: Verified correct area outputs through base-type references.
- Structural Integrity: Adhered to the strict hierarchical alignment for the project structure.
- Java 8+ (Abstract Classes, Inheritance, Polymorphism, Math API)
- Figure: The abstract base defining the area calculation contract.
- Square: A concrete figure implementing area logic based on side length.
- Circle: A concrete figure implementing area logic based on radius.
- GeometryLauncherApp: The application entry point for verifying calculations.
16.0
28.274333882308138
Project Structure:
JavaBasics_Task_333/
├── src/
│ └── com/yurii/pavlenko/
│ ├── app/
│ │ └── GeometryLauncherApp.java
│ └── geometry/
│ ├── types/
│ │ ├── Square.java
│ │ └── Circle.java
│ └── Figure.java
├── LICENSE
├── TASK.md
├── THEORY.md
└── README.md
Code
package com.yurii.pavlenko.app;
import com.yurii.pavlenko.geometry.Figure;
import com.yurii.pavlenko.geometry.types.Square;
import com.yurii.pavlenko.geometry.types.Circle;
public class GeometryLauncherApp {
public static void main(String[] args) {
Figure square = new Square(4);
Figure circle = new Circle(3);
System.out.println(square.area());
System.out.println(circle.area());
}
}package com.yurii.pavlenko.geometry;
public abstract class Figure {
public abstract double area();
}package com.yurii.pavlenko.geometry.types;
import com.yurii.pavlenko.geometry.Figure;
public class Square extends Figure {
private double side;
public Square(double side) {
this.side = side;
}
@Override
public double area() {
return side * side;
}
}package com.yurii.pavlenko.geometry.types;
import com.yurii.pavlenko.geometry.Figure;
public class Circle extends Figure {
private double radius;
public Circle(double radius) {
this.radius = radius;
}
@Override
public double area() {
return Math.PI * radius * radius;
}
}This project is licensed under the MIT License.
Copyright (c) 2026 Yurii Pavlenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...
License: MIT