Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write a code in Java for the following: Write a program that allows the user to convert temperatures to Fahrenheit, Celsius and Kelvin, then

Please write a code in Java for the following:

image text in transcribedimage text in transcribed

Write a program that allows the user to convert temperatures to Fahrenheit, Celsius and Kelvin, then displays the values. The program is to be menu driven. Validate user input for acceptable values. The program should display the following menu of selections: 1. Convert Fahrenheit to Celsius 2. Convert Celsius to Fahrenheit 3. Convert Fahrenheit to Kelvin 4. Display Data 5. Quit Program Enter your selection (1-5): Assignment Specific Requirements: 1) Write main to control the program. Within main when one temperature is converted all temperature types - Fahrenheit, Celsius and Kelvin - should be calculated and store here in local variables for output. Temperatures conversions are only to be done within the methods designed for that purpose. Do not convert any temperature outside of those methods. 2) Write a return method named showMenu that displays the menu. This method should not accept any arguments but should return a valid selection value (15). Output an appropriate error message to the user if the choice is not acceptable, then redisplay the menu. DO NOT CALL SHOWMENU FROM INSIDE THE METHOD. 3) Write a return method named getTemperature(). It has one argument, the type of temperature being requested as a String data type - Fahrenheit, or Celsius. This value should be used in the prompt to the user. See sample run. It should prompt the user to input a temperature and return that value to the calling statement. No input validation is required. 4) Write a return method named calcCelsius, which accepts the Fahrenheit temperature as an argument. The method should return the converted value to main for storage. Convert degrees F to C using the following formula: i. C=(5/9)(F32) 5) Write a return method named calcFahrenheit, which accepts the Celsius temperature as an argument. The method should return the converted value to main for storage. Convert degrees C to F using the following formula: i. F=(C9/5)+32 6) Write a return method named calcKelvin, which accepts the Fahrenheit temperature as an argument. Convert degrees F to K using the following formula: i. K=C+273.15 ii. or iii. K=(5/9)(F32)+273.15 7) Create a void method named displayData(), which receives three (3) arguments - the Fahrenheit, Celsius and Kelvin values. Format output to two digits passed the decimal point. Trailing zeros should display. All decimal points should align in the columns of data when output. 8) For every value entered, all three temperatures should be calculated Fahrenheit, Celsius, and Kelvin. 9) The program should continue to execute until the user enters 5 to quit the program. 10) The program should accept both positive and negative temperatures. 11) If the user selects an invalid choice from the menu, the program should display an appropriate error message and not return to main until a valid selection is made

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

3. How would you address the problems that make up the situation?

Answered: 1 week ago

Question

2. What recommendations will you make to the city council?

Answered: 1 week ago