The calculation puts out 0.0 for the Celsius. Can you help me? The textbook solu
ID: 3630013 • Letter: T
Question
The calculation puts out 0.0 for the Celsius. Can you help me? The textbook solution did not give me any help.import javax.swing.JOptionPane;
import javax.swing.JLabel;
import javax.swing.JFrame;
public class LabelFrame extends JFrame
{
private JLabel label; // converted temperature
public LabelFrame()
{
super( "Temperature Conversions" );
// obtain user input from JOptionPane input dialogs
String first =
JOptionPane.showInputDialog( "Enter Fahrenheit Temperature" );
// convert String input to int values for use in calculation
double num = Double.parseDouble( first );
double celsius = ( 5/9 * ( num - 32 ));
// displays temperature conversion
JLabel label = new JLabel( null, "The Celsius Temperture is " +celsius,
"Celsius Temperaturer", JLabel. );
add( label );
} // end method LabelFrame
} // end class LabelFrame
import javax.swing.JFrame;
public class LabelTest
{
public static void main( String args[] )
{
LabelFrame labelFrame = new LabelFrame(); // creates TemperatureConversion
labelFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
labelFrame.setSize( 300, 300 ); // set frame size
labelFrame.setVisible( true ); // display frame
} // end method main
} // end class TemperatureConversionTest
Explanation / Answer
replace this
double celsius = ( 5/9 * ( num - 32 ));
with
double celsius = ( 5.0/9.0 * ( num - 32 ));
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.