Question
Write a Java program to continue creating your own user-defined methods and introduce some do-while loops. Write two value-returning methods called farToCel() and celToFar(). These
Write a Java program to continue creating your own user-defined methods and introduce some do-while loops.
Write two value-returning methods called farToCel() and celToFar(). These two methods will convert temperatures from Fahrenheit to Celsius and Celsius to Fahrenheit respectively. They will each take a single int parameter and return the converted value as an int.
Write an additional value-returning method called displayMenu() to display a three item menu and read input from the user which is their selection and return that as a char. Consider using the Character class method toUpperCase() to narrow the number of choices from six {F, f, C, c, Q, q} to three {F, C, Q}.
Note that displayMenu() has no parameters. The displayMenu() method MUST only return valid values.
Start by calling displayMenu() within a do-while loop in the main() method which will capture the return value of displayMenu() into a char variable. This value will be used to determine what type of conversion is to be done and the loop will terminate when the user enters Q.
The other do-while loop is in the displayMenu() method. We would stay in the displayMenu() method until the user chooses a valid selection. By doing so, this method can never return bad selections to the main() method.
Once you have mastered your displayMenu() method, you can proceed to the other two. Also, note that displayMenu() is not responsible for reading the temperatures; the main() method will do this based on the choice made by the user.
The calculation for Fahrenheit to Celsius is: The calculation for Celsius to Fahrenheit is: c 9 5 32 Your output should resemble: Please select one of the following: F To convert Fahrenheit to Celsius C To convert Celsius to Fahrenheit Q To Quit Choice f Enter the Fahrenheit temperature: 32 The Temperature 32 Fahrenheit is 0 CelsiusStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started