Question: Use Chapter 1 1 Kilometer Converter application code ( Section 1 1 . 7 ) to write Temperature Converter application to convert degrees Fahrenheit into

Use Chapter 11 Kilometer Converter application code (Section 11.7) to write Temperature Converter application to convert degrees Fahrenheit into degrees Celsius ((F -32)*5/9). Use a lambda expression. Below is the application code for the kilometer Converter.
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.geometry.Pos;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.Button;
import javafx.event.EventHandler;
import javafx.event.ActionEvent;
/**
* Kilometer Converter application
*/
public class KiloConverter extends Application
{
// Fields
private TextField kiloTextField;
private Label resultLabel;
public static void main(String[] args)
{
// Launch the application.
launch(args);
}
@Override
public void start(Stage primaryStage)
{
// Create a Label to display a prompt.
Label promptLabel = new Label("Enter a distance in kilometers:");
// Create a TextField for input.
kiloTextField = new TextField();
// Create a Button to perform the conversion.
Button calcButton = new Button("Convert");
// Register the event handler.
calcButton.setOnAction(new CalcButtonHandler());
// Create an empty Label to display the result.
resultLabel = new Label();
// Put the promptLabel and the kiloTextField in an HBox.
HBox hbox = new HBox(10, promptLabel, kiloTextField);
// Put the HBox, calcButton, and resultLabel in a VBox.
VBox vbox = new VBox(10, hbox, calcButton, resultLabel);
// Set the VBox's alignment to center.
vbox.setAlignment(Pos.CENTER);
// Set the VBox's padding to 10 pixels.
vbox.setPadding(new Insets(10));
// Create a Scene.
Scene scene = new Scene(vbox);
// Add the Scene to the Stage.
primaryStage.setScene(scene);
// Set the stage title.
primaryStage.setTitle("Kilometer Converter");
// Show the window.
primaryStage.show();
}
/*
* Event handler class for calcButton
*/
class CalcButtonHandler implements EventHandler
{
@Override
public void handle(ActionEvent event)
{
// Get the kilometers.
Double kilometers = Double.parseDouble(kiloTextField.getText());
// Convert the kilometers to miles.
Double miles = kilometers *0.6214;
// Display the results.
resultLabel.setText(String.format("%,.2f miles", miles));
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!