Starting from:

$30

Lab Assignment #5 Solution

Lab Objectives
Be able to write Java programs with

Decision Structures
Input Validation
Loops
Be able to test and debug a program



Submission instruction: create a script file that, for each test, display the Java program source code (e.g. cat task1.java) followed by test runs. Submit the script file on blackboard along the Lab 5 link.
Task #1 Built-in Program Testing
Rewrite your BMI program so that the program will continue to run as long as the user enters the Yes choice (use while loop). Your program output should look something like




Welcome to my BMI calculation

Please enter ….



Your calculated BMI is …

Your BMI is in … range

Do you want to calculate another BMI? Enter Y or y for Yes.




Required testing: run the program at least four times.




Task #2 Print Pattern
Use for loop to print out n lines in the following patterns (here n=4).

*

**

***

****

Also use while loop or do-while loop to allow user to enter n values and to run the program multiple times.

Required testing: run the program for n = 4, n=6, and n=10.

More products