Title | Programming Exercise 2.4 |
---|---|
Course | Programming Fundamentals |
Institution | 香港理工大學 |
Pages | 1 |
File Size | 58.7 KB |
File Type | |
Total Downloads | 53 |
Total Views | 129 |
Programming Exercise...
COMP1011 Chapter 2 #4
Page 1 of 1
COMP1011 — Programming Fundamentals Assignments for Chapter 2 #4 (User Input/Output) Name:
ID:
Score:
Lab Day of the Week (Mon, Tue, Wed, Thu, Fri): Lab Time Slot:
Lab Venue:
Lab Group:
[Programming Exercise] 1. (4 marks) Now, it’s your turn to write your own program. A quantity known as the body mass index (BMI) is used to calculate the risk of weight-related health problems. BMI is computed by the formula BM I =
w h 2 100
where w is the weight in kilograms and h is height in centimeters. A BMI of about 20 to 25 is considered “normal”; below 20 is considered too thin; and above 25 is considered too fat. Write a program that accepts weight and height (both are integer values) and outputs the BMI. An example execution is shown below. Weight in kg? 78 Height in cm? 184 BMI = 23.03875236294896 Use BMI as the class name and thus the filename must be BMI.java. Key Point: The BMI is likely to be a fractional value. Can you produce it? 2. (4 marks) Write an application that inputs temperature in degrees Celsius and outputs the temperature in degrees Fahrenheit. Use JOptionPane for input and output. The formula to convert degrees Celsius to equivalent degrees Fahrenheit is: F ahrenheit = 1.8 × Celsius + 32 Note: The input can be a fractional value. To convert a string to a double value, use Double.parseDouble(), for example, String input; double d; ... d = Double.parseDouble(input);
-End-...