Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

use the JOptionPane to write a program that allows the user to convert a tempera

ID: 3642298 • Letter: U

Question

use the JOptionPane to write a program that allows the user to convert a temperature given in degrees from either celsius to fahrenheit or fahrenheit to celsius.use the following formulas: degrees_c=5(degrees_f-32)/9 , degrees_f=(9(degrees_c)/5)+32) ,prompt the user to enter a temperature and either a C or c for celsius or and F or f for Fahrenheit.convert the temperature to fahrenheit if celsius is entered or to celsius if fahrenheit is entered.display the result in a readable formate ,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 an 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, offer the user Yes and No buttons to end execution .

Explanation / Answer

please rate. Keep file name as OptionPaneTemperature.java import javax.swing.JOptionPane; public class OptionPaneTemperature { JOptionPane display; String message = "Enter temperature: "; boolean finished = false; double convertToFarenhiet(double celcius){ double farenheit = 0.0; farenheit = celcius * 9 / 5 + 32.0 ; return farenheit; } double convertToCelcius(double farenheit){ double celcius = 0.0; celcius = 5 * (farenheit - 32.0) / 9; return celcius; } public void processInput(String input){ double temperature = 0.0; String output=""; try{ char t = input.charAt(input.length() - 1 ); input = input.substring(0,input.length()-1); input.trim(); if(t=='c'||t=='C'){ temperature = convertToFarenhiet(Double.parseDouble(input)); output = " degree F "; } if(t=='f'||t=='F'){ temperature = convertToCelcius(Double.parseDouble(input)); output = " degree C " ; } }catch(Exception e){ JOptionPane.showMessageDialog(null, "Error invalid input", "Error", JOptionPane.ERROR_MESSAGE); return; } output = "Temperature is "+temperature+output; JOptionPane.showMessageDialog(null, output, "Conversion", JOptionPane.PLAIN_MESSAGE); } public OptionPaneTemperature(){ while(!finished){ String input = JOptionPane.showInputDialog(null, message, "Temperature conversion", JOptionPane.QUESTION_MESSAGE); processInput(input); int result = JOptionPane.showConfirmDialog(null, "Do you want to continue","Temperature conversion", JOptionPane.YES_NO_OPTION); if(result != JOptionPane.YES_OPTION){ finished = true; } } } public static void main(String[] args){ new OptionPaneTemperature(); } }