Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Console IO and Arithmetic Expressions The goal of this exercise is to learn more about variables ( page 4 0 ) , named constants (

Console IO and Arithmetic Expressions
The goal of this exercise is to learn more about variables (page 40), named constants
(page 43), numeric data types (page 45), console input using the Scanner class (page 46),
and arithmetic expressions (page 50). Create a new BlueJ project (lab2), and then create a
class called Conversion in it. First edit the comment section at the top to include a brief
description of the program, your name, date, etc.
Body Mass Index (BMI) is a measure of health based on weight. It can be calculated by
taking your weight in kilograms and dividing it by the square of your height in meters.
Write a program that prompts the user to enter a weight in pounds and height in inches,
and displays the BMI. Note that one pound is 0.45359237 kilograms, and one inch is
0.0254 meters. Define named constants in your program for these decimals.
How to do it:
1- Import the Scanner class at the top of your program right below the block-comment
2- Create a Scanner object named input at the beginning of your main method
3- Declare two named constants POUND_TO_KILOGRAM and INCH_TO_METER
3- Declare three variables of type double named weight, height, and bmi
4- Add a println-statement(s) that will display a header block identifying you, the course,
and the lab number (see sample output below). This information will appear on the
screen when you run the program. It is used to identify who the output belongs to if
the output is printed separate from the source program.
5- Prompt for and read in the weight in pounds, and height in inches
6- Convert the weight to kilogram, and height to meter
7- Compute the BMI
8- Display the BMI on the screen with only two digits after the decimal point
9- Compile and run the program. If it generates the output shown below, copy the output and
paste it inside a block comment at the end of your source program.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions