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

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 ));


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote