When submitting this lab, submit a .java file called ShirtSize, and create the following structure in Eclipse:
Package Name:week4
Class Name:ShirtSize
Sometimes it can be difficult to order a men’s shirt online. It would be helpful to have a program tell you what size shirt you should buy based on the measurement of the customer’s chest. Write a program that will ask the user for the customer’s chest size in inches. The program will then display what shirt size should be ordered. Use the following table to determine the appropriate shirt size:
Chest Measurement (in inches)
|
Shirt Size
|
Less than 38”
|
S
|
Greater than or equal to 38” and less than 40”
|
M
|
Greater than or equal to 40” and less than 43”
|
L
|
Greater than or equal to 43” and less than 46”
|
XL
|
Greater than or equal to 46”
|
XXL
|
The following steps will help you write the program:
Step 1:Using the Scanner, use an in.nextLine() statement to prompt the user for the measurement of the customer’s chest. Store the user's input into a variable called input
Step 2:Convert the user input into an integer using Integer.parseInt() and store the converted value into a variable called chestSize.
Step 3:Write an if statement that checks to see if chestSize is less than 38 inches.
Step 4:If step 2 is true, printthe appropriate shirt size (S).
Step 5:Use an else if statement to see if chestSize is greater than or equal to 38 inches and less than 40 inches. (Remember that&&is the 'and' operator)
Step 6:If step 4 is true, print the appropriate shirt size(M).
Step 7:Use an else if statement to see if chestSize is greater than or equal to 40 inches and less than 43 inches.
Step 8:If step 6 is true, print the appropriate shirt size (L).
Step 9:Use an else if statement to see if chestSize is greater than or equal to 43 inches and less than 46 inches.
Step 10:If step 8 is true, print the appropriate shirt size (XL).
Step 11:Use an else statement to print the appropriate shirt size (XXL) of none of the above conditions are true.
|