0% found this document useful (0 votes)
9 views13 pages

Java BMI Calculator Journal Template

The document outlines a Java journal template for a BMI calculator program, detailing the problem definition, expected inputs, program functionality, outputs, and pseudocode. It includes specific examples for testing the program, error handling, and thorough commenting for clarity. The final section provides a link to the completed program hosted on an IDE platform.

Uploaded by

rtorwaz24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views13 pages

Java BMI Calculator Journal Template

The document outlines a Java journal template for a BMI calculator program, detailing the problem definition, expected inputs, program functionality, outputs, and pseudocode. It includes specific examples for testing the program, error handling, and thorough commenting for clarity. The final section provides a link to the completed program hosted on an IDE platform.

Uploaded by

rtorwaz24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Java Journal Template

Directions: Follow the directions for each part of the journal template. Include in your response
all the elements listed under the Requirements section. Prompts in the Inspiration section are
not required; however, they may help you to fully think through your response.
Remember to review the Touchstone page for entry requirements, examples, and grading
specifics.

Name: Richard Torres Romero


Date: June 5th, 2025
Final IDE Program Join Link:<e.g.,
[Link] >

1
PART 1: Defining Your Problem

Task
State the problem you are planning to solve.

Requirements
● Describe the problem you are trying to solve.
● Describe any input data you expect to use.
● Describe what the program will do to solve the problem.
● Describe any outputs or results the program will provide.

Inspiration
When writing your entry below, ask yourself the following questions:
● Is your problem clearly defined?

● Why do you want to solve this particular problem?

● What source(s) of data do you believe you will need? Will the user need to supply that data,
or will you get it from an external file or another source?
● Will you need to interact with the user throughout the program? Will users continually need to
enter data in and see something to continue?
● What are your expected results or what will be the end product? What will you need to tell a
user of your program when it is complete?

Problem statement (in plain language)


Many people want a quick, reliable way to determine whether their current weight is in a healthy
range. My program will calculate a user’s Body Mass Index (BMI) from their height and weight, then
classify the BMI as Underweight, Normal weight, Overweight, or Obese according to widely-used
clinical guidelines.

Expected input data

1. The measurement system the user wishes to use (Imperial or Metric).

2. If Imperial: weight in pounds and height in inches.

3. If Metric: weight in kilograms and height in metres.

What the program will do

● Prompt the user to choose a measurement system.

2
● Collect weight and height in the chosen units.

● Validate that both numbers are positive.

● Apply the appropriate BMI formula:


– Imperial BMI = (weight × 703) / (height²)
– Metric BMI = weight / (height²)

● Round the result to one decimal place.

● Compare the result to standard BMI ranges and assign the correct weight-status category.

Outputs / results

● The calculated BMI value (one decimal).

● The corresponding weight-status category.

● A short welcome or error message when appropriate.

PART 2: Working Through Specific Examples

Task
Write down clear and specific steps to solve a simple version of your problem you identified in Part 1.

Requirements
Complete the three steps below for at least two distinct examples/scenarios.
● State any necessary input data for your simplified problem.
● Write clear and specific steps in English (not Java) detailing what the program will do to solve
the problem.
● Describe the specific result of your example/scenario.

Inspiration
When writing your entry below, ask yourself the following questions:
● Are there any steps that you don’t fully understand? These are places to spend more time
working out the details. Consider adding additional smaller steps in these spots.
● Remember that a computer program is very literal. Are there any steps that are unclear? Try
giving the steps of your example/scenario to a friend or family member to read through and
ask you questions about parts they don’t understand. Rewrite these parts as clearly as you

3
can.
● Are there interesting edge cases for your program? Try to start one of your
examples/scenarios with input that matches this edge case. How does it change how your
program might work?

Example Inputs (user Step-by-step Expected result


types) actions (English,
not Java)

1 – Imperial, 1. Display menu and “Your BMI is


typical values receive “1”.
1 (Imperial) 150 lb 68 in (58) 22.8 - Normal
2. Ask for weight; weight”
receive 150.
3. Ask for height;
receive 68.
4. Verify both > 0.

5. Compute BMI = (150 × 703) / (68²) 22.8.

6. Compare 22.8 to ranges “Normal weight”.

2 – Metric, 1. Display menu and “Your BMI is


2 (Metric) 90 kg 1.60 m
edge case receive “2”. 35.2 - Obese”
(short adult) 2. Ask for weight;
receive 90.
3. Ask for height;
receive 1.60.
4. Verify both > 0.
5. Compute BMI = 90 / (1.60²) 35.2.

6. Compare 35.2 to ranges “Obese”.

Edge-case thoughts

● If the user enters 0 or a negative number, the program must reject the input and terminate
with an error message.

● If the user chooses an invalid menu option, the program must also terminate gracefully.

4
5
PART 3: Generalizing Into Pseudocode

Task
Write out the general sequence your program will use, including all specific examples/scenarios you
provided in Part 2.

Requirements
● Write pseudocode for the program in English but refer to Java program elements where they
are appropriate. The pseudocode should represent the full functionality of the program, not
just a simplified version. Pseudocode is broken down enough that the details of the program
are no longer in any paragraph form. One statement per line is ideal.

Help With Writing Pseudocode


● Here are a few links that can help you write pseudocode with examples. Remember to check
out part 3 of the Example Journal Template Submission if you have not already. Note:
everyone will write pseudocode differently. There is no right or wrong way to write it, other
than to make sure you write it clearly and in as much detail as you can so that it should be
easy to convert to code later.
○ [Link]
○ [Link]

Inspiration
When writing your entry below, ask yourself the following questions:
● Do you see common program elements and patterns in your specific examples/scenarios in
Part 2, like variables, conditionals, functions, loops, and classes? These should be part of
your pseudocode for the general sequence as well.
● Are there places where the steps for your examples/scenarios in Part 2 diverged? These may
be places where errors may occur later in the project. Make note of them.
● When you are finished with your pseudocode, does it make sense, even to a person that does
not know Java? Aim for the clearest description of the steps, as this will make it easier to
convert into program code later.

6
START PROGRAM

PRINT welcome message


PRINT "Choose measurement system:"
PRINT "1) Imperial (pounds / inches)"
PRINT "2) Metric (kilograms / metres)"
READ selection INTO choice

IF choice == 1 THEN
PROMPT "Enter weight in pounds: "
READ pounds
PROMPT "Enter height in inches: "
READ inches
IF pounds <= 0 OR inches <= 0 THEN
PRINT "Error: weight and height must be positive."
EXIT PROGRAM
END IF
SET bmi = (pounds * 703) / (inches * inches)
CALL displayResult(bmi)
ELSE IF choice == 2 THEN
PROMPT "Enter weight in kilograms: "
READ kg
PROMPT "Enter height in metres: "
READ metres
IF kg <= 0 OR metres <= 0 THEN
PRINT "Error: weight and height must be positive."
EXIT PROGRAM
END IF
SET bmi = kg / (metres * metres)
CALL displayResult(bmi)
ELSE
PRINT "Invalid selection. Program terminates."
END IF

FUNCTION displayResult(bmi)
PRINT "Your BMI is " + bmi rounded to 1 decimal
IF bmi < 18.5 THEN category = "Underweight"
ELSE IF bmi < 25 THEN category = "Normal weight"
ELSE IF bmi < 30 THEN category = "Overweight"
ELSE category = "Obese"
END IF
PRINT "Weight Status: " + category
END FUNCTION

7
END PROGRAM

8
PART 4: Testing Your Program

Task
While writing and testing your program code, describe your tests, record any errors, and state your
approach to fixing the errors.

Requirements
● For at least one of your test cases, describe how your choices for the test helped you
understand whether the program was running correctly or not.
For each error that occurs while writing and testing your code:
● Record the details of the error from your IDE. A screenshot or copy-and-paste of the text into
the journal entry is acceptable.
● Describe what you attempted in order to fix the error. Clearly identify which approach was the
one that worked.

Inspiration
When writing your entry below, ask yourself the following questions:
● Have you tested edge cases and special cases for the inputs of your program code? Often
these unexpected values can cause errors in the operation of your program.
● Have you tested opportunities for user error? If a user is asked to provide an input, what
happens when they give the wrong type of input, like a letter instead of a number, or vice
versa?
● Did the outcome look the way you expected? Was it formatted correctly?

● Does your output align with the solution to the problem you coded for?

Test Reason for What I expected Actual Error details & fix
case test outcome

150 lb / 68 in Validate typical Imperial Correct N/A –


BMI 22.8 Normal weight
(Example 1) path passed

90 kg / 1.60 m Validate Metric path and “Obese” Correct N/A –


BMI 35.2 Obese
(Example 2) boundary passed

9
Select option 3 User menu error “Invalid selection” then Correct N/A –
(invalid) handling exit passed

Enter 0 kg or 0 Guard against non- “Error: weight and height must Correct N/A –
inches positive inputs be positive.” passed

Intentional Confirm Input- Java’s Added try…catch


typo: type program mismatch InputMismatchException block in final code
“abc” instead of crashes and exception ; program terminated version to display a
a number note the friendlier message
stack trace (see code
comments).

PART 5: Commenting Your Program

Task
Submit your full program code, including thorough comments describing what each portion of the
program should do when working correctly.

Requirements
● The purpose of the program and each of its parts should be clear to a reader that does not
know the Java programming language.

Inspiration
When writing your entry, you are encouraged to consider the following:
● Is each section or sub-section of your code commented to describe what the code is doing?

● Give your code with comments to a friend or family member to review. Add additional
comments to spots that confuse them to make it clearer.

/*
* [Link]
* A console application that computes Body Mass Index (BMI)
* and classifies the result according to standard weight ranges.
* Author: Richard Torres Romero
* Date: 5 June 2025
*/

10
import [Link];
import [Link];

public class BMICalculator {

// Entry point of the program.


public static void main(String[] args) {

Scanner scanner = new Scanner([Link]); // Reads user input

[Link]("Welcome to the BMI Calculator.");


[Link]("Choose measurement system:");
[Link]("1) Imperial (pounds / inches)");
[Link]("2) Metric (kilograms / metres)");

try {
int choice = [Link](); // Read menu choice

// Branch based on the user's selection.


if (choice == 1) { // --- Imperial path ---
[Link]("Enter weight in pounds: ");
double pounds = [Link]();

[Link]("Enter height in inches: ");


double inches = [Link]();

// Validate inputs to avoid division by zero or negative values.


if (pounds <= 0 || inches <= 0) {
[Link]("Error: weight and height must be positive numbers.");
return; // Early exit on invalid data
}

double bmi = (pounds * 703) / (inches * inches); // Formula for Imperial units
showResult(bmi);

} else if (choice == 2) { // --- Metric path ---


[Link]("Enter weight in kilograms: ");
double kg = [Link]();

[Link]("Enter height in metres: ");


double metres = [Link]();

if (kg <= 0 || metres <= 0) {

11
[Link]("Error: weight and height must be positive numbers.");
return;
}

double bmi = kg / (metres * metres); // Formula for Metric units


showResult(bmi);

} else { // Anything other than 1 or 2


[Link]("Invalid selection. Program terminates.");
}

} catch (InputMismatchException ex) {


// Catches cases where the user types letters instead of numbers.
[Link]("Input error: please enter numeric values only. Program terminates.");
} finally {
[Link](); // Always close the scanner to free resources
}
}

/**
* Displays the BMI rounded to one decimal and classifies it.
* @param bmi the calculated Body Mass Index
*/
private static void showResult(double bmi) {
[Link]("Your BMI is %.1f%n", bmi);

String category; // Holds the classification text

if (bmi < 18.5) {


category = "Underweight";
} else if (bmi < 25) {
category = "Normal weight";
} else if (bmi < 30) {
category = "Overweight";
} else {
category = "Obese";
}

// Present the classification to the user.


[Link]("Weight Status: " + category);
}
}

12
PART 6: Your Completed Program

Task
Provide the IDE link to your full program code.

Requirements
● The program must work correctly with all the comments included in the program.

Inspiration
● Check before submitting your Touchstone that your final version of the program is running
successfully.

IDE share link: <e.g., [Link] >

13

You might also like