Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribedimage text in transcribed

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 Celsius

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

How many moles are present in 3.55 1024 Pb atoms?

Answered: 1 week ago

Question

=+How should it be delivered?

Answered: 1 week ago

Question

=+4 How does one acquire a global mindset?

Answered: 1 week ago