Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions bmi-calculator/BMICalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// BMI CALCULATOR USING JAVA - FIRST OPEN SOURCE CONTRIBUTION THROUGH THIS PROJECT

import java.util.Scanner;

public class BMICalculator {

Check warning on line 5 in bmi-calculator/BMICalculator.java

View workflow job for this annotation

GitHub Actions / java-linter

[reviewdog] reported by reviewdog 🐶 Abbreviation in name 'BMICalculator' must contain no more than '1' consecutive capital letters. Raw Output: /github/workspace/./bmi-calculator/BMICalculator.java:5:14: warning: Abbreviation in name 'BMICalculator' must contain no more than '1' consecutive capital letters. (com.puppycrawl.tools.checkstyle.checks.naming.AbbreviationAsWordInNameCheck)

Check warning on line 5 in bmi-calculator/BMICalculator.java

View workflow job for this annotation

GitHub Actions / java-linter

[reviewdog] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./bmi-calculator/BMICalculator.java:5:1: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck)
public static void main(String[] args) {

Check warning on line 6 in bmi-calculator/BMICalculator.java

View workflow job for this annotation

GitHub Actions / java-linter

[reviewdog] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./bmi-calculator/BMICalculator.java:6:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)

Check warning on line 6 in bmi-calculator/BMICalculator.java

View workflow job for this annotation

GitHub Actions / java-linter

[reviewdog] reported by reviewdog 🐶 'method def modifier' has incorrect indentation level 4, expected level should be 2. Raw Output: /github/workspace/./bmi-calculator/BMICalculator.java:6:5: warning: 'method def modifier' has incorrect indentation level 4, expected level should be 2. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
// This program calculates BMI based on user input

Scanner scanner = new Scanner(System.in);

Check warning on line 9 in bmi-calculator/BMICalculator.java

View workflow job for this annotation

GitHub Actions / java-linter

[reviewdog] reported by reviewdog 🐶 'method def' child has incorrect indentation level 8, expected level should be 4. Raw Output: /github/workspace/./bmi-calculator/BMICalculator.java:9:9: warning: 'method def' child has incorrect indentation level 8, expected level should be 4. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)

System.out.println("Welcome to the BMI Calculator!");

Check warning on line 11 in bmi-calculator/BMICalculator.java

View workflow job for this annotation

GitHub Actions / java-linter

[reviewdog] reported by reviewdog 🐶 'method def' child has incorrect indentation level 8, expected level should be 4. Raw Output: /github/workspace/./bmi-calculator/BMICalculator.java:11:9: warning: 'method def' child has incorrect indentation level 8, expected level should be 4. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)

// Get weight from user
System.out.print("Please enter your weight in kilograms: ");

Check warning on line 14 in bmi-calculator/BMICalculator.java

View workflow job for this annotation

GitHub Actions / java-linter

[reviewdog] reported by reviewdog 🐶 'method def' child has incorrect indentation level 8, expected level should be 4. Raw Output: /github/workspace/./bmi-calculator/BMICalculator.java:14:9: warning: 'method def' child has incorrect indentation level 8, expected level should be 4. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
double weight = scanner.nextDouble();

Check warning on line 15 in bmi-calculator/BMICalculator.java

View workflow job for this annotation

GitHub Actions / java-linter

[reviewdog] reported by reviewdog 🐶 'method def' child has incorrect indentation level 8, expected level should be 4. Raw Output: /github/workspace/./bmi-calculator/BMICalculator.java:15:9: warning: 'method def' child has incorrect indentation level 8, expected level should be 4. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)

// Get height from user
System.out.print("Please enter your height in meters: ");

Check warning on line 18 in bmi-calculator/BMICalculator.java

View workflow job for this annotation

GitHub Actions / java-linter

[reviewdog] reported by reviewdog 🐶 'method def' child has incorrect indentation level 8, expected level should be 4. Raw Output: /github/workspace/./bmi-calculator/BMICalculator.java:18:9: warning: 'method def' child has incorrect indentation level 8, expected level should be 4. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
double height = scanner.nextDouble();

Check warning on line 19 in bmi-calculator/BMICalculator.java

View workflow job for this annotation

GitHub Actions / java-linter

[reviewdog] reported by reviewdog 🐶 'method def' child has incorrect indentation level 8, expected level should be 4. Raw Output: /github/workspace/./bmi-calculator/BMICalculator.java:19:9: warning: 'method def' child has incorrect indentation level 8, expected level should be 4. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)

// Calculate BMI
double bmi = weight / (height * height);

// Print the result
System.out.printf("Your BMI is: %.2f\n", bmi);

// Interpret the BMI value
if (bmi < 18.5) {
System.out.println("You are underweight.");
} else if (bmi >= 18.5 && bmi < 25) {
System.out.println("You have a normal weight.");
} else if (bmi >= 25 && bmi < 30) {
System.out.println("You are overweight.");
} else {
System.out.println("You are obese.");
}

// Close the scanner
scanner.close();
}
}
34 changes: 34 additions & 0 deletions bmi-calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# BMI Calculator

This is a simple Java program that calculates your Body Mass Index (BMI) based on your weight and height.

## How to Run

1. Make sure you have Java JDK 21 installed.
2. Open a terminal in this folder.
3. Compile the program:
```
javac BMICalculator.java
```
4. Run the program:
```
java BMICalculator
```

## What It Does

- Asks you for your weight (in kilograms) and height (in meters)
- Calculates your BMI
- Tells you if you are underweight, normal, overweight, or obese

## JDK Version

- OpenJDK Runtime Environment Temurin-21 (or any OpenJDK 21)

## IDE Used

- Visual Studio Code (VS Code)

---

*This project was created as a beginner contribution for the Grow-with-Open-Source/Java-Projects repository.*
Loading