CSC 340 Lab Instructions for January 24, 2011
Choose a machine in BB 454 that you will be comfortable using
throughout the rest of the semester and log in using your MSUNet2K
Start either JCreator or jGRASP, whichever you prefer. (JCreator is Windows only, jGRASP is both Windows and Linux).
Create a new Java source code file ( File -> New ...) and enter (or copy and paste) the following Java program:
** CSC 340 Lab exercise for January 23, 2012
** Written by Dr. Lyle
** January 10, 2010
** See Exercise 2.33, page 69, Deitel & Deitel, 9th edition
public class BMI
public static void main( String args )
Scanner input = new Scanner( System.in );
System.out.print("Enter your name: ");
String name = input.nextLine(); // Get user's name
System.out.print("Enter your height (in inches): ");
int height = input.nextInt(); // Get their height
System.out.print("Enter your weight (in pounds): ");
int weight = input.nextInt(); // Get their weight
double BMI = weight * 703.0 / (height * height); //Calculate BMI
System.out.printf("%s, your BMI is %.2f\n", name, BMI);
System.out.println("For reference, BMI ranges are:");
System.out.println("Underweight:\tless than 18.5");
System.out.println("Normal:\tbetween 18.5 and 24.9");
System.out.println("Overweight:\tbetwen 25 and 29.9");
System.out.println("Obese:\t\t30 or greater");
// All Through!
Save the file as BMI.java
Compile and run the program.
Try introducing various errors into the program (misspelled reserved
words, misspelled variable names, missing semicolons, mismatched
parentheses, etc.) and recompile to get a feeling for the types of
error messages produced by the compiler.
Save your source code to a thumb drive or email it to yourself. The hard drives in the lab may be cleaned at any time without notice, so save your work somewhere else.
See Dr. Lyle if you would like a Subversion repository on the
departmental Linux server. This will provide you with version
control of all of your work that will be accessible from anywhere.