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

In Java Assuming that C is a Celsius temperature, the following formula converts

ID: 3681435 • Letter: I

Question

In Java
Assuming that C is a Celsius temperature, the following formula converts the temperature to Fahrenheit:
F=1.8 *C /32
Assuming that F is a Fahrenheit temperature, the following formula converts the temperature to Celsius:
C=5/9 * (F-32)

Create a JavaFX application that allows the user to enter a temperature. The application should have
button components as described as follows:


A button that reads “Convert to Fahrenheit” If the user clicks this button, the application treats the
temperature entered as Celsius and converts it to Fahrenheit.


A button that reads “Convert to Celsius” If the user clicks this button, the application treats the
temperature entered as Fahrenheit and converts it to Celsius.

Here is an example of KiloConverterController

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

public class KilometerConverterController
{
@FXML
private Button convertButton;

@FXML
private TextField kilometerTextField;

@FXML
private Label outputLabel;

@FXML
private Label promptLabel;

// This method is called when the FXML file is loaded
public void initialize()
{
// Perform any necessary initialization here.
}
  
// Event listener for the convertButton
public void convertButtonListener()
{
final double CONVERSION_FACTOR = 0.6214;
  
// Get the kilometers from the TextField.
String str = kilometerTextField.getText();
  
// Convert kilometers to miles.
double miles = Double.parseDouble(str) * CONVERSION_FACTOR;
  
// Display the converted distance.
outputLabel.setText(str + " kilometers is " + miles + " miles.");
}
}

Explanation / Answer

I have written the code for temperature converson in java fx.

Working code:

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
public class TemperatureConvertor
{
@FXML
private Button ConvertToFahrenheit;
   private Button ConvertToCelsius;
@FXML
private TextField TemperatureTextField;
@FXML
private Label outputLabel;
@FXML
private Label promptLabel;
// This method is called when the FXML file is loaded
public void initialize()
{
// Perform any necessary initialization here.
}
  
// Event listener for the ConvertToFahrenheit Button
public void ConvertToFahrenheitListener()
{
final double CONVERSION_FACTOR = 1.8;
  
// Get the celsius temperature from the TextField.
String str = TemperatureTextField.getText();
  
// Convert celsius to fahrenheit.
double fahrenheit = (Double.parseDouble(str) * CONVERSION_FACTOR)/32;
  
// Display the converted temperature.
outputLabel.setText(str + " fahrenheit is " + fahrenheit);
}

public void ConvertToCelsiusListener()
{
final double CONVERSION_FACTOR = 0.555;
  
// Get the fahrenheit temperature from the TextField.
String str = TemperatureTextField.getText();
  
// Convert fahrenheit to celsius.
double fahrenheit = CONVERSION_FACTOR*(Double.parseDouble(str) - 32);
  
// Display the converted temperature.
outputLabel.setText(str + " celsius is " + celsius);
}


}

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