New version page

UGA CSCI 1301 - Lab4

Documents in this Course
Load more
Upgrade to remove ads

This preview shows page 1 out of 3 pages.

Save
View Full Document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Upgrade to remove ads
Unformatted text preview:

CSCI 1301 – Lab 9/08/08 Due date: 09/14/2008 Exercise #1 The purpose of this exercise is to apply your knowledge about variables, arithmetic expressions, output statements and the Scanner class discussed during the lectures. Write a java program that contains a class called BodyMassIndex with a main method that computes the body mass index. The body mass index (BMI) is a measurement of body fat which compares a person's weight and height. weight(kgs.) BMI = height 2 (meters) In this lab, you are asked to write a java program that computes the body mass index of a user. The user will enter his/her weight in pounds and his/her height in feet and inches (both are integers) and compute the person’s BMI. Your program should ask the user to enter his/her height in feet and inches. For example, a person 8 feet 7 inches tall will enter 8 and 7 separated by space. Your program should compute the user’s height in inches, a foot is twelve inches. As you can observe the BMI formula above is specified in kilograms (kgs.) and meters so before computing the BMI, your program needs to perform some computations to convert pounds to kilograms in the following way: weight in Kilograms = weight in Pounds / 2.2 Analogously, the program needs to convert inches to meters as follows: 1 inch = 0.0254 meters Then, your program will compute the user’s BMI and displays the result on the screen. The output of your program should look similar to this: Weight: 190.0lbs. Height: 6' 2" BMI: 24.44556320150558 You should format the output text in columns using the '\t' escape sequence as discussed during class. Compile and run your program. After you have completed this exercise, demonstrate it to your lab instructor.Exercise #2 The goal of this exercise is to familiarize you with String variables and the use of some of the methods of the class String. Write a java program that contains a class called PlayingWithStrings with a main method that performs the following actions: Write a declaration of a String variable called bestSwimmer and initialize it “MICHAEL F. WHELPS”. Write an assignment statement to replace W in the string bestSwimmer with a capital P using the appropriate String method. Write a declaration for a String variable called firstName and initialize it to the substring containing the first 7 characters of the String bestSwimmer (use a string method to obtain the substring). Write a declaration for a String variable called lastName and use the appropriate String method to initialize lastName to the string containing the last 6 characters of the String bestSwimmer. Write a declaration of a String variable called middleInitial and initialize it to the substring of characters in bestSwimmer with indexes between 8 and 9 using the appropriate String method. Write several assignments statements to convert the characters in the string variables firstName and lastName to lowercase. Use the appropriate String method to replace the first letter of the firstName and lastName by its corresponding capital letter. Write a declaration of a String variable called reversedName and initialize it to the concatenation of lastName, firstName and middleInitial so the name is in the following format: Last Name, First Name MiddleInitial. Display the following short biography inserting the variables reversedName, firstName, middleInitial and lastName in the appropriate locations: reversedName –, June 30, 1985, Baltimore, Maryland. firstName middleInitial lastName is an American swimmer. lastName has won 14 career Olympic gold medals, the most by any Olympian. lastName went a perfect 8for8 in Beijing, breaking Mark Spitz's single-Games record for gold medals. As of September 2008, firstName lastName holds seven world records in swimming. After you have completed this exercise, demonstrate it to your lab instructor.WebCT Submission After you have completed both exercises in this lab, upload the file Earnings.java inWebCT and submit it to receive


View Full Document
Download Lab4
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lab4 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lab4 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?