Question: In this assignment, you will write a Java program that repeatedly asks the user for their height in inches. Each time, you should convert their
In this assignment, you will write a Java program that repeatedly asks the user for their height in inches. Each time, you should convert their height to full feet and inches and print the result. You should repeat this process until the user chooses to quit.
Here is a sample run of the program (user input is in red):
Enter your height in inches: 68
You are 5 feet, 8 inches tall
Do you want to go again? (y/n) y
Enter your height in inches: 72
You are 6 feet tall Do you want to go again? (y/n) Y
Enter your height in inches: -1
Error: height must be positive
Do you want to go again? (y/n) n
Requirements
This program should contain a single class (called Proj3) with a main method. Your program should compile and run in BlueJ. To get the number of whole feet, take the height in inches divided by 12. (Remember that integer division will only keep the whole number portion, and not the decimal, which is exactly what you want in this case.) To get the number of inches leftover, find the remainder of dividing the height in inches by 12 (hint: use the % operator). You will need to use a do-while loop or a while loop to repeat the process until the user says they want to quit.
Here are some additional requirements/tips: You may assume that the user will always type in a whole number for the height in inches You may assume that the user will always type in a single character for whether they want to go again. See Project 2 for details on how to read a single character from user input. If the user's height ever converts to exactly some whole number of feet with no inches leftover (like 6 feet exactly), then you should JUST print the corresponding number of feet and not "0 inches". See the 6 feet example in the sample run of the program above. You will need to use an if-statement to help you only print the leftover inches when you need to. If the user enters a negative height, you should print an error (see the sample run above) and NOT convert their height to feet/inches. Again, you will need to use an if-statement. Your program should work if the user enters either 'y' or 'Y' for wanting to go again. If the user enters ANYTHING except 'y' or 'Y', you can assume that means that they do not want to continue, and then quit your loop. Your program should exactly match the example above when it runs (except for the values of the numbers depending on the user input)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
