Skip to content

YuriiJavaDev/JavaBasics_Task_333_V0.1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Geometry Library: Polymorphic Area Calculation (JavaBasics_Task_333_V0.1)

📖 Description

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 ($side^2$ and $pi*r^2$) within their respective classes while providing a consistent interface for the application.

📋 Requirements Compliance

  • Abstract Logic: Established the Figure class as a blueprint for all geometric entities.
  • Formula Encapsulation: Implemented specific area formulas within Square and Circle.
  • Mathematical Accuracy: Utilized Math.PI for 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.

🚀 Architectural Stack

  • Java 8+ (Abstract Classes, Inheritance, Polymorphism, Math API)

🏗️ Implementation Details

  • 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.

📋 Expected result

16.0
28.274333882308138

💻 Code Example

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;
    }
}

⚖️ License

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

About

This is a tutorial project. JavaBasics_Task_333_V0.1 Geometry Library Foundation: implementing a polymorphic architecture for area calculation across different geometric figures (Square and Circle). 160426_1056

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages