Skip to content

gabrielml/bmi-java-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

👹 Java BMI Calculator

A Java Web Application to calculate the Body Mass Index.

Requirements

  • Input: Weight in Kilograms (Kg)
  • Input: Height in Meters (m)
  • Output: BMI rounded to 2 decimal places.

Formula

$$\text{BMI} = \frac{\text{weight (kg)}}{\text{height (m)}^2}$$

🔄 Migration: >_ From Console to Jakarta EE Web App 🌐

Why the Change?

To achieve the "Honors" grade, the application was evolved from a command-line tool to a dynamic web application using Java Servlets and JSP.

Key Architectural Differences

Feature Console Version Web Version (Servlets/JSP)
User Interface Terminal (Scanner) Browser (HTML Form)
Logic Execution Local JVM Apache Tomcat Container
Data Handling Primitive variables HTTP Request/Responses

Implementation Details

  1. Separation of Concerns: The UI is handled by index.jsp, while the logic is isolated in BMIServlet.java.
  2. Server Environment: Migrated from a local Java execution to a managed Servlet Container (Tomcat 10).
  3. Validation: Input validation now occurs at the server-side before rendering the result back to the user.

🛠️ Technical Specifications

This project was built following the Jakarta EE 10 specifications, ensuring a modern and standardized Java Web environment.

Component Technology / Version
Runtime Java JDK 21+
Web Specification Jakarta EE 10 (Servlet 5.0)
Server Apache Tomcat 10.1.53
IDE IntelliJ IDEA Community Edition
Plugin SmartTomcat
CSS Baseline Normalize.css v8.0.1

🚀 Key Technical Highlights

  • Jakarta Servlet API: Implemented a Controller-based architecture using HttpServlet to handle POST requests and state logic.
  • Cross-Browser Consistency: Integrated normalize.css to eliminate default browser inconsistencies (margins, button rendering, and font-scaling).
  • Resource Management: Organized static assets (CSS, Icons) into a dedicated web root structure (/css, /img) for optimal deployment.
  • Atomic Git Workflow: Development was managed through a feature-branching strategy, utilizing git stash for context switching and descriptive, conventional commits.

Manual Web Configuration (IntelliJ Community Edition)

  • Plugin: Utilized SmartTomcat to manage server execution and updated the "Deployment Directory" (SmartTomcat Settings) to target the webapp folder specifically.
  • Library Management: Manually linked servlet-api.jar and jsp-api.jar from Tomcat /lib to the project dependencies.
  • Deployment: Configured web.xml for servlet mapping instead of using automated IDE wizards.

📁 Final Project Structure ("The Anatomy of a Java Web App")

From a "Standard Java layout" to a Maven or Gradle style structure (the industry standard for Web Apps)

bmi-calculator/
├── src/
│   └── main/
│       ├── java/               (Backend Servlets | LOGIC)
│       │   └── BMIServlet.java     (Original code moved here and updated [Previous file "BMICalculator.java"])
│       └── webapp/             (Fronted JSPs | UI)
│           ├── css/
│           │   ├── normalize.css
│           │   └── style.css
│           ├── img/
│           │   └── favicon.ico
│           ├── index.jsp           (HTML Form)
│           └── WEB-INF/        (Deployment Configuration)
│               └── web.xml         (The configuration file | "The Brain")
├── .gitignore
└── README.md

🔗 Useful Links


Developed by Gabriel as part of the Java Web Development Honors Challenge.

Releases

No releases published

Packages

 
 
 

Contributors