Question: Write a JavaFX application that converts a given velocity value from miles per hour to kilometers per hour or kilometers per hour to miles per

Write a JavaFX application that converts a given velocity value from miles per hour to kilometers per hour or kilometers per hour to miles per hour. Include a pair of radio buttons to indicate the direction of the conversion, and a pair of text fields (with appropriate labels) to allow input of the numbers. Also include a "Convert" button, a "Clear" button, and a empty label where error messages can be displayed if necessary.
By default, the "MPH to KPH" radio button should be selected. Whichever radio button is selected, the other text field should be set as not editable. For example when the "MPH to KPH" radio button is selected, the KPH text field should be uneditable. Also, whenever either radio button is clicked, both text fields and the error label should be cleared of text.
Of course, the user's input is received as text and must be parsed to a double. If the user's input cannot be be converted (because it is non-numeric), an exception will be thrown when the input is parsed. Catch the exception and output an appropriate error message in the label at the bottom of the scene.
Helpful hint:The controls can be laid out in rows by using HBoxes, although a GridPane will work better for the TextFields and their associated labels. The vertical alignment can achieved by placing the HBoxes and GridPane in an outer VBox.
Conversion Factor: 1 mph =1.609344 kph

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 Programming Questions!