Skip to content

Java MVC Circle Project. This is a Java Back-End project built with Maven, following the Model-View-Controller (MVC) design pattern. The goal of the project is to create a simple `Circle` class that can calculate and store geometric data (area and perimeter) based on a given radius.

Notifications You must be signed in to change notification settings

alexpjava/CircleMVC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

CircleMVC โ€” Java Back-End Project Built with Maven

๐Ÿ“˜ Project Description

This is a Java Back-End project built with Maven, following the Model-View-Controller (MVC) design pattern.
The goal of the project is to create a simple Circle class that can calculate and store geometric data (area and perimeter) based on a given radius.

Later, the project will include a SQL database to store all circle data entered via the keyboard.
Each entry will record:

  • The radius
  • The calculated perimeter
  • The calculated area

Table of contents


๐Ÿงฎ 1. Features

  • Input a circleโ€™s radius.
  • Compute the area and perimeter.
  • Display results through the console view.
  • Future feature: Store results in a SQL database.

๐Ÿ—๏ธ 2. Architecture. Explanation of the MVC Pattern

The project follows the MVC (Model-View-Controller) pattern:

  • Model: Represents the data and business logic (e.g., the Circle class).
  • View: Handles user interaction (e.g., console input/output).
  • Controller: Coordinates communication between the Model and the View.
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   View     โ”‚ <---> โ”‚ Controller  โ”‚ <---> โ”‚   Model    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Layer Role Class
Model Represents the data and business logic Circle.java
View Handles user interaction (input/output) CircleView.java
Controller Coordinates interaction between model and view CircleController.java


๐Ÿ“ฆ 3. Project Structure

java-mvc-circle/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main/
โ”‚   โ”‚   โ”œโ”€โ”€ java/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ com/example/circle/
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ model/
โ”‚   โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ Circle.java
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ view/
โ”‚   โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ CircleView.java
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ controller/
โ”‚   โ”‚   โ”‚           โ””โ”€โ”€ CircleController.java
โ”‚   โ”‚   โ””โ”€โ”€ resources/
โ”‚   โ””โ”€โ”€ test/
โ”‚       โ””โ”€โ”€ java/
โ”‚           โ””โ”€โ”€ com/example/circle/
โ”‚               โ””โ”€โ”€ CircleTest.java
โ”œโ”€โ”€ pom.xml
โ””โ”€โ”€ README.md

๐Ÿงญ 4. UML Diagram in Mermaid Format

classDiagram
    direction TB

    class Circle {
        - double radius
        + Circle(double radius)
        + getRadius() double
        + setRadius(double radius)
        + calculatePerimeter() double
        + calculateArea() double
        + toString() String
    }

    class CircleView {
        - Scanner scanner
        + CircleView()
        + requestRadius() double
        + displayResults(perimeter double, area double) void
        + displayMessage(message String) void
    }

    class CircleController {
        - CircleView view
        + CircleController(view CircleView)
        + start() void
    }

    CircleController --> CircleView : uses
    CircleController --> Circle : creates/manages
Loading

๐Ÿงญ 4.1. Full UML Diagram (Model-View-Controller)

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚        Circle              โ”‚  <<Model>>
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ - radius: double           โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ + Circle(radius: double)   โ”‚
โ”‚ + getRadius(): double      โ”‚
โ”‚ + setRadius(radius: double)โ”‚
โ”‚ + calculatePerimeter(): double โ”‚
โ”‚ + calculateArea(): double  โ”‚
โ”‚ + toString(): String       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

             โ–ฒ
             โ”‚ uses
             โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚       CircleController     โ”‚  <<Controller>>
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ - view: CircleView         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ + CircleController(v: CircleView) โ”‚
โ”‚ + start(): void            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
             โ”‚
             โ”‚ calls
             โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚        CircleView          โ”‚  <<View>>
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ - scanner: Scanner         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ + CircleView()             โ”‚
โ”‚ + requestRadius(): double  โ”‚
โ”‚ + displayResults(p: double, a: double): void โ”‚
โ”‚ + displayMessage(msg: String): void          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ’ป 5. Base Code for Each Class

๐Ÿงฑ Model: Circle.java

package com.teoria.circulo.model;

public class Circle {
    private double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    public double calculatePerimeter() {
        return 2 * Math.PI * radius;
    }

    public double calculateArea() {
        return Math.PI * Math.pow(radius, 2);
    }

    @Override
    public String toString() {
        return "Circle [radius=" + radius + 
               ", perimeter=" + calculatePerimeter() + 
               ", area=" + calculateArea() + "]";
    }
}

๐ŸŽจ View: CircleView.java

package com.teoria.circulo.view;

import java.util.Scanner;

public class CircleView {
    private Scanner scanner;

    public CircleView() {
        scanner = new Scanner(System.in);
    }

    public double requestRadius() {
        System.out.print("Enter the circle's radius: ");
        return scanner.nextDouble();
    }

    public void displayResults(double perimeter, double area) {
        System.out.printf("Perimeter: %.2f%n", perimeter);
        System.out.printf("Area: %.2f%n", area);
    }

    public void displayMessage(String message) {
        System.out.println(message);
    }
}

๐Ÿงญ Controller: CircleController.java

package com.teoria.circulo.controller;

import com.teoria.circulo.model.Circle;
import com.teoria.circulo.view.CircleView;

public class CircleController {
    private CircleView view;

    public CircleController(CircleView view) {
        this.view = view;
    }

    public void start() {
        double radius = view.requestRadius();
        Circle circle = new Circle(radius);

        double perimeter = circle.calculatePerimeter();
        double area = circle.calculateArea();

        view.displayResults(perimeter, area);

        // Later: save to database
        // saveToDB(circle);
    }
}

๐Ÿš€ Main Class

package com.teoria.circulo;

import com.teoria.circulo.view.CircleView;
import com.teoria.circulo.controller.CircleController;

public class Main {
    public static void main(String[] args) {
        CircleView view = new CircleView();
        CircleController controller = new CircleController(view);
        controller.start();
    }
}

๐Ÿงฉ 6. Future Expansion: SQL Database Connection

Later, the project will add:

  • A CircleDAO class (in model.dao) to handle CRUD operations with SQL.
  • A circles table in the database with columns:
CREATE TABLE circles (
    id INT AUTO_INCREMENT PRIMARY KEY,
    radius DOUBLE,
    perimeter DOUBLE,
    area DOUBLE
);
  • The controller will call CircleDAO.insert(circle) after calculating results.

โš™๏ธ 7. Requirements

  • Java 17 or later
  • Maven 3.8+
  • (Optional later) MySQL or PostgreSQL for data persistence

๐Ÿš€ 8. How to Run the Project

  1. Clone this repository:

    git clone https://github.com/alexpjava/java-mvc-circle.git
    cd java-mvc-circle
  2. Build the project with Maven:

    mvn clean install
  3. Run the application:

    mvn exec:java -Dexec.mainClass="com.example.circle.Main"

๐Ÿง  9. Future Improvements

  • Add SQL database integration to store circle data.
  • Add unit tests with JUnit.
  • Add a graphical user interface (optional).
  • Generate and include the UML diagram.

๐Ÿ“„ 10. License

This project is open-source and available under the MIT License.


โœ๏ธ 11. Author

AlexP
GitHub: @alexpjava
Email: alexp.java@gmail.com

About

Java MVC Circle Project. This is a Java Back-End project built with Maven, following the Model-View-Controller (MVC) design pattern. The goal of the project is to create a simple `Circle` class that can calculate and store geometric data (area and perimeter) based on a given radius.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages