This program is the same as program 5 on chapter 3 of \"Java: An introduction to
ID: 3645700 • Letter: T
Question
This program is the same as program 5 on chapter 3 of "Java: An introduction to problem solving by Savitch 6th Ed". In that exercise you were asked to write a program that allowed the user to convert the temperature for Celsius to Fahrenheit and vice versa. This was the description for program n.5 in chapter 3:Write a program that allows the user to convert a temperature given in degrees from Celsius to Farenheit or vice versa. Prompt the user to enter a temperature and either C or a c for Celsius and an F or f for fahrenheit. Convert the temperature. Display the result in a readable format. If anything other that C,c,F,f is entered, print an error message and stop.
The following program comes from the same text. Here is the description for the modification:
Repeat program 5 of Chapter 3, but use a loop so the user can convert other temperatures. If the user enters a letter other than C or F - in either uppercase or lowercase - after a temperature, print a error message and ask the user to reenter a valid selection. Do not ask the user to reenter the numeric portion of the temperature again, however. After each conversion, ask the user to type Q or p to quit or to press any other key to repeat the loop and perform another conversion.
PLEASE, TYPE FULL PROGRAM FOR KARMA POINTS.
Explanation / Answer
public class Converter { public Converter() { } // Method to convert from degrees Celcius to degrees Fahrenheit public static float celciusToFahrenheit(float degCelcius) { float degFahrenheit; degFahrenheit = degCelcius * 9/5 + 32; return degFahrenheit; } // Method to convert from degrees Fahrenheit to degrees Celcius public static float fahrenheitToCelcius(float degFahrenheit) { float degCelcius; degCelcius = (degFahrenheit - 32) * 5/9; return degCelcius; } // Method to convert from degrees Celcius to degrees Kelvin public static float celciusToKelvin(float degCelcius) { float degKelvin; degKelvin = degCelcius + 273.15f; return degKelvin; } // Method to convert from degrees Kelvin to degrees Celcius public static float kelvinToCelcius(float degKelvin) { float degCelcius; degCelcius = degKelvin - 273.15f; return degCelcius; } // Main method demonstrating usage of above methods public static void main(String[] args) { System.out.print("100 degrees Celcius in Fahrenheit is: "); System.out.println(celciusToFahrenheit(100)); System.out.print("-40 degrees Fahrenheit in Celcius is: "); System.out.println(fahrenheitToCelcius(-40)); System.out.print("0 degrees Celcius in Kelvin is: "); System.out.println(celciusToKelvin(0)); // to convert from Kelvin to Fahrenheit, combine two methods: System.out.print("373.15 degrees Kelvin in Fahrenheit is: "); System.out.println(celciusToFahrenheit(kelvinToCelcius(373.15f))); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.