Using a Java Program. Write a program that will display a temperature conversion
ID: 3672322 • Letter: U
Question
Using a Java Program.
Write a program that will display a temperature conversion table. The user will input the beginning Fahrenheit temperature, the ending Fahrenheit temperature, and the temperature increment for display in the table. The program should then convert and display the temperature results in the form “Fahrenheit to
Celsius”. The formula for the conversion is as follows:
Celsius = ( 5 / 9 ) * ( Fahrenheit – 32 )
Please No JTextArea
Your program should make use of the JOptionPane class. Use the same class for BOTH input and output.
Explanation / Answer
--->Here I have taken 5/9 value as 0.55556 because compiler treats 5/9 as 0,but we have to add 5%9(modulus) to obtain correct Celsius values.Therefore we take 5/9 as 0.55556.
package fahrenheit;
import javax.swing.*;
import javax.swing.JOptionPane;
public class Fahrenheit {
public static void main(String[] args) {
String s_f_start,s_f_end,s_f_difference;
double fstart,fend,fdifference;
double cstart,cend,cdifference;
s_f_start = JOptionPane.showInputDialog("Enter Starting Temperature");
s_f_end=JOptionPane.showInputDialog("Enter ending Temperature");
fstart=Double.parseDouble(s_f_start);
fend=Double.parseDouble(s_f_end);
fdifference=fend-fstart;
System.out.println("Fahrenheit Temperatres are STemp ETemp Dtemp ");
System.out.println(fstart+" "+fend+" "+fdifference);
cstart=(0.55556)*(fstart-32);
cend=(0.55556)*(fend-32);
cdifference=(0.55556)*(fdifference-32);
//JOptionPane.showMessageDialog( null, "The Product is " + fn*sn, "Product", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"Start Tempereatre in Celsius is = " +cstart+" End Tempereatre in Celsius is = "+cend+" Difference Tempereatre in Celsius is = "+cdifference,"Difference",JOptionPane.INFORMATION_MESSAGE);
System.out.println("Celsius temperatures are CStart CEnd CDifference");
System.out.println(cstart+" "+cend+" "+cdifference);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.