Skip to content

A responsive, multi-user calculator web app built with Spring Boot and Spring MVC for Software Architecture (ARSW). Supports basic arithmetic operations, RESTful APIs, and a stylish UI with real-time feedback. Showcases layered architecture and full-stack Java web development.

License

Notifications You must be signed in to change notification settings

AnderssonProgramming/calculator-mvc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงฎ Spring MVC Calculator

A modern, responsive calculator web application built with Spring Boot and Spring MVC architecture. This multi-user calculator supports basic arithmetic operations and features a beautiful, intuitive user interface.

Calculator Demo Java Maven License AWS

๐ŸŒŸ Features

โœจ Calculator Operations

  • โž• Addition: Add two numbers with precision
  • โž– Subtraction: Subtract numbers accurately
  • โœ–๏ธ Multiplication: Multiply numbers with decimal support
  • โž— Division: Divide numbers with zero-division protection
  • ๐Ÿ”„ All Clear (AC): Reset calculator to initial state
  • โŒซ Backspace: Delete last entered character

๐ŸŽจ User Experience

  • ๐ŸŽฏ Modern UI: Beautiful gradient design with glassmorphism effects
  • ๐Ÿ“ฑ Responsive: Works perfectly on desktop, tablet, and mobile devices
  • โŒจ๏ธ Keyboard Support: Full keyboard navigation and shortcuts
  • โšก Real-time Calculations: Instant feedback and calculations
  • ๐Ÿšจ Error Handling: User-friendly error messages and validations

๐Ÿข Enterprise Features

  • ๐Ÿ‘ฅ Multi-User Support: Designed for concurrent user access
  • ๐Ÿ”— REST API: Clean, documented API endpoints
  • โœ… Comprehensive Testing: Full unit and integration test coverage
  • ๐Ÿ“Š Health Monitoring: Application health check endpoints
  • ๐Ÿ›ก๏ธ CORS Support: Cross-origin resource sharing enabled

๐Ÿ—๏ธ Architecture

This application implements the Spring MVC (Model-View-Controller) architectural pattern:

๐Ÿ“‹ Layer Structure

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Presentation      โ”‚  โ† Static HTML/CSS/JS (View)
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚   Controller        โ”‚  โ† REST API Endpoints 
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚   Service           โ”‚  โ† Business Logic (Model)
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚   Data Transfer     โ”‚  โ† DTOs for API Communication
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐ŸŽฏ Components

  • ๐ŸŽฎ Controller Layer: CalculatorController - Handles HTTP requests and responses
  • โš™๏ธ Service Layer: CalculatorService - Contains business logic for calculations
  • ๐Ÿ“ฆ DTO Layer: CalculatorRequest/CalculatorResponse - Data transfer objects
  • ๐Ÿ–ผ๏ธ View Layer: Static HTML/CSS/JavaScript for user interface

๐Ÿš€ Quick Start

Prerequisites

  • โ˜• Java 17+ (JDK 17 or higher)
  • ๐Ÿ“ฆ Maven 3.6+
  • ๐Ÿ–ฅ๏ธ IDE (IntelliJ IDEA, Eclipse, or VS Code recommended)

๐Ÿ”ง Installation & Setup

  1. Clone the repository

    git clone https://github.com/AnderssonProgramming/calculator-mvc.git
    cd calculator-mvc
  2. Build the project

    mvn clean compile
  3. Run tests (optional but recommended)

    mvn test
  4. Start the application

    mvn spring-boot:run
  5. Access the calculator

alt text

๐Ÿ”Œ Alternative Ways to Run

Using Java directly:

mvn clean package
java -jar target/calculator-mvc-0.0.1-SNAPSHOT.jar

Using your IDE:

  • Import the project as a Maven project
  • Run CalculatorMvcApplication.java as a Java application

๐Ÿ“ก API Documentation

Base URL: http://localhost:8081/api/calculator

๐Ÿ” Endpoints

1. Calculate Operation

  • URL: POST /calculate
  • Description: Performs arithmetic calculations
  • Content-Type: application/json

Request Body:

{
  "operand1": 10.5,
  "operand2": 5.2,
  "operation": "add"
}

Supported Operations:

  • add or + - Addition
  • subtract or - - Subtraction
  • multiply or * - Multiplication
  • divide or / - Division
  • clear or ac - All Clear

Success Response:

{
  "result": 15.7,
  "operation": "add",
  "success": true,
  "errorMessage": null
}

Error Response:

{
  "result": 0,
  "operation": null,
  "success": false,
  "errorMessage": "Cannot divide by zero"
}

2. Health Check

  • URL: GET /health
  • Description: Check if the calculator service is running
  • Response: "Calculator service is running"

๐Ÿงช API Testing Examples

Using cURL:

# Addition
curl -X POST http://localhost:8081/api/calculator/calculate \
  -H "Content-Type: application/json" \
  -d '{"operand1": 15, "operand2": 25, "operation": "add"}'

# Division with error handling
curl -X POST http://localhost:8081/api/calculator/calculate \
  -H "Content-Type: application/json" \
  -d '{"operand1": 10, "operand2": 0, "operation": "divide"}'

# Health check
curl http://localhost:8081/api/calculator/health

๐Ÿงช Testing

Running Tests

# Run all tests
mvn test

# Run specific test class
mvn test -Dtest=CalculatorServiceTest

# Run tests with coverage report
mvn clean test jacoco:report

๐Ÿ“Š Test Coverage

  • Service Layer: 100% method coverage
  • Controller Layer: Complete API endpoint testing
  • Integration Tests: Full application context testing

๐ŸŽฏ Test Categories

  • Unit Tests: Individual component testing
  • Integration Tests: Spring context and HTTP request testing
  • Error Handling: Edge cases and exception scenarios

๐Ÿ“ Project Structure

calculator-mvc/
โ”œโ”€โ”€ ๐Ÿ“„ pom.xml                           # Maven configuration
โ”œโ”€โ”€ ๐Ÿ“„ README.md                         # This file
โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ main/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ java/edu/eci/arsw/calculator_mvc/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ CalculatorMvcApplication.java    # Main application class
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ controller/
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“„ CalculatorController.java    # REST API controller
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ dto/
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ CalculatorRequest.java       # Request DTO
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“„ CalculatorResponse.java      # Response DTO
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“ service/
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ ๐Ÿ“„ CalculatorService.java       # Business logic
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“ resources/
โ”‚   โ”‚       โ”œโ”€โ”€ ๐Ÿ“„ application.properties           # App configuration
โ”‚   โ”‚       โ””โ”€โ”€ ๐Ÿ“ static/
โ”‚   โ”‚           โ”œโ”€โ”€ ๐Ÿ“„ index.html                   # Main UI
โ”‚   โ”‚           โ””โ”€โ”€ ๐Ÿ“ js/
โ”‚   โ”‚               โ””โ”€โ”€ ๐Ÿ“„ calculator.js            # Frontend logic
โ”‚   โ””โ”€โ”€ ๐Ÿ“ test/
โ”‚       โ””โ”€โ”€ ๐Ÿ“ java/edu/eci/arsw/calculator_mvc/
โ”‚           โ”œโ”€โ”€ ๐Ÿ“„ CalculatorMvcApplicationTests.java
โ”‚           โ”œโ”€โ”€ ๐Ÿ“ controller/
โ”‚           โ”‚   โ””โ”€โ”€ ๐Ÿ“„ CalculatorControllerTest.java
โ”‚           โ””โ”€โ”€ ๐Ÿ“ service/
โ”‚               โ””โ”€โ”€ ๐Ÿ“„ CalculatorServiceTest.java

โš™๏ธ Configuration

Application Properties

# Application settings
spring.application.name=calculator-mvc
server.port=8081

# Error handling
server.error.include-message=always
server.error.include-binding-errors=always

# Logging
logging.level.edu.eci.arsw.calculator_mvc=DEBUG
logging.level.org.springframework.web=INFO

๐Ÿ”ง Customization Options

  • Port: Modify server.port in application.properties
  • Logging: Adjust logging levels for different packages
  • CORS: Configure allowed origins in CalculatorController

๐ŸŽจ User Interface

๐Ÿ’ก Features

  • Glassmorphism Design: Modern frosted glass effect
  • Responsive Layout: Adapts to different screen sizes
  • Smooth Animations: Button hover effects and transitions
  • Color-Coded Buttons: Different colors for numbers, operators, and functions
  • Real-time Display: Shows both expression and result

โŒจ๏ธ Keyboard Shortcuts

  • Numbers: 0-9 keys
  • Operations: +, -, *, /
  • Calculate: Enter or =
  • Clear: Escape key
  • Delete: Backspace key
  • Decimal: . key

๐Ÿ› Troubleshooting

Common Issues

1. Port Already in Use

Error: Web server failed to start. Port 8081 was already in use.

Solution: Change the port in application.properties or stop the process using port 8081.

2. Maven Build Issues

Error: Could not find or load main class

Solution: Run mvn clean compile and ensure Java 17+ is installed.

3. Application Won't Start

Error: APPLICATION FAILED TO START

Solution: Check logs for specific errors, verify Java version and dependencies.

๐Ÿ”ง Debug Mode

Run with debug logging:

mvn spring-boot:run -Dspring-boot.run.profiles=debug

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“ Development Guidelines

  • Follow Spring Boot best practices
  • Maintain test coverage above 90%
  • Use meaningful commit messages
  • Update documentation for new features

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Spring Framework Team - For the excellent Spring Boot framework
  • Font Awesome - For the beautiful icons
  • Stack Overflow Community - For countless solutions and inspiration

๐Ÿ”ฎ Future Enhancements

  • Scientific Calculator: Add trigonometric and logarithmic functions
  • History Feature: Store and display calculation history
  • Memory Functions: M+, M-, MR, MC operations
  • Themes: Multiple UI themes and dark mode
  • Keyboard Layout: Virtual keyboard display
  • Unit Converter: Length, weight, temperature conversions
  • Export Results: Save calculations to file
  • User Profiles: Personal calculation preferences

โญ If you found this project helpful, please give it a star! โญ

Made with โค๏ธ Spring Boot


Happy Calculating! ๐Ÿงฎโœจ

About

A responsive, multi-user calculator web app built with Spring Boot and Spring MVC for Software Architecture (ARSW). Supports basic arithmetic operations, RESTful APIs, and a stylish UI with real-time feedback. Showcases layered architecture and full-stack Java web development.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published