In graphics applications, treating different geometric objects through a unified interface is essential for scalability. This project establishes a basic Shape Abstraction model. By defining an abstract Shape class, we create a mandatory requirement for any geometric entity to provide its area. The Circle class serves as the first concrete implementation, encapsulating the specific mathematical logic required to calculate the area of a circular object based on its radius.
-
Core Abstraction: Defined an abstract
Shapeclass to act as a general template. -
Contract Fulfillment: Implemented the mandatory
area()method in theCirclesubclass. -
Mathematical Logic: Applied the circle area formula (
$3.14 \times r^2$ ) within the specific implementation. - Execution Verification: Confirmed accurate calculation results through a dedicated launcher application.
- Java 8+ (Abstract Classes, Inheritance, Basic Mathematics)
- Shape: The abstract foundation defining the area calculation contract.
- Circle: A concrete shape implementation managing radius data and area logic.
- GraphicsLauncherApp: The entry point for testing the geometric calculations.
12.56
Project Structure:
JavaBasics_Task_336/
├── src/
│ └── com/yurii/pavlenko/
│ ├── app/
│ │ └── GraphicsLauncherApp.java
│ └── graphics/
│ ├── types/
│ │ └── Circle.java
│ └── Shape.java
├── LICENSE
├── TASK.md
├── THEORY.md
└── README.md
Code
package com.yurii.pavlenko.app;
import com.yurii.pavlenko.graphics.types.Circle;
public class GraphicsLauncherApp {
public static void main(String[] args) {
Circle circle = new Circle(2.0);
System.out.println(circle.area());
}
}package com.yurii.pavlenko.graphics;
public abstract class Shape {
public abstract double area();
}package com.yurii.pavlenko.graphics.types;
import com.yurii.pavlenko.graphics.Shape;
public class Circle extends Shape {
private double radius;
public Circle(double radius) {
this.radius = radius;
}
@Override
public double area() {
return 3.14 * 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