Question

Design JavaFX application with 7 labels and one textfield where user enters input inches. When user...

Design JavaFX application with 7 labels and one textfield where user enters input inches. When user enters his choice and presses enter key to complete input, program outputs resulting yards, feet, and inches.

  • Use class P5 that extends Application with start method in it, and class P5Pane that extends GridPane. The only instance variables for P5Pane class are inputInches where user enters input inches, and three labels: outYards, outFeet, and outInches where program displays result of conversion. Use the following names for instance variables:

                           private Label outYards, outFeet, outInches;

                           private TextField inputInches;

  • All other variables should be local where needed.
  • Title bar of the output window must have your first and last name and not mine at the end of the given title.
  • Provide also UML with classes P5, P5Pane, Application, and GridPane. The boxes for Application and GridPane can only have top part filled, since they are Java classes. Relationships must be specified.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Working code implemented in Java and appropriate comments provided for better understanding:

Here I am attaching code for these files:

  • P5.java
  • P5Pane.java

Source code for P5.java:

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.scene.control.TextField;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;

/**
* Program converts inches to yards, feet, and inches using javafx.
*/

public class P5 extends Application
{
public void start(Stage stage)
{
Scene scene = new Scene(new P5Pane(), 300, 150);
  
stage.setTitle("Converting inches to yards,feet,inches");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}

Source code for P5Pane.java:

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.scene.control.TextField;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.event.ActionEvent;
import javafx.geometry.HPos;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;

/**
* Program converts inches to yards, feet, and inches using javafx.
*/

public class P5Pane extends GridPane
{
private Label outYards,outFeet,outInches;
private TextField inputInches;

public P5Pane()
{
Label inputLabel = new Label("Input Inches in Range 0 to 100000 :");
GridPane.setHalignment(inputLabel, HPos.RIGHT);

Label yardsLabel = new Label("Yards:");
GridPane.setHalignment(yardsLabel, HPos.RIGHT);

Label feetLabel = new Label("Feet:");
GridPane.setHalignment(feetLabel, HPos.RIGHT);

Label inchesLabel = new Label("Inches:");
GridPane.setHalignment(inchesLabel, HPos.RIGHT);

outYards = new Label("---");
GridPane.setHalignment(outYards, HPos.RIGHT);

outFeet = new Label("---");
GridPane.setHalignment(outFeet, HPos.RIGHT);

outInches = new Label("---");
GridPane.setHalignment(outInches, HPos.RIGHT);

inputInches = new TextField();
inputInches.setPrefWidth(50);
inputInches.setAlignment(Pos.CENTER);
inputInches.setOnAction(this::calculate);

setAlignment(Pos.CENTER);
setHgap(20);
setVgap(10);
setStyle("-fx-background-color: limegreen");

add(inputLabel, 0, 0);
add(inputInches, 1, 0);
add(yardsLabel,0 ,1 );
add(feetLabel, 0, 2);
add(inchesLabel, 0, 3);
add(outYards, 1, 1);
add(outFeet, 1, 2);
add(outInches, 1, 3);
}

public void calculate(ActionEvent event)
{
int number = Integer.parseInt(inputInches.getText());
int yard = (int) (number/36);
int yard_rem = (int) (number%36);
int feet = (int) (yard_rem/12);
int feet_rem = (int) (yard_rem%12);
int inches = feet_rem;

outYards.setText(yard+"");
outFeet.setText(feet+"");
outInches.setText(inches+"");   
}
}

UML Diagram:

<<Java Class>> P5 (default package) P50 start(Stage):void Smain(String):void «Java Class>> CP5Pane (default package) - outYar

Sample Output Screenshots:

Converting inches to yards, feet,inches Input Inches in Range 0 to 100000 : 777 Yards: 21 Feet: Inches: 9

Hope it helps, if you like the answer give it a thumbs up. Thank you.

Add a comment
Know the answer?
Add Answer to:
Design JavaFX application with 7 labels and one textfield where user enters input inches. When user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I. User Interface Create a JavaFX application with a graphical user interface (GUI) based on the...

    I. User Interface Create a JavaFX application with a graphical user interface (GUI) based on the attached “GUI Mock-Up”. Write code to display each of the following screens in the GUI: A. A main screen, showing the following controls: • buttons for “Add”, “Modify”, “Delete”, “Search” for parts and products, and “Exit” • lists for parts and products • text boxes for searching for parts and products • title labels for parts, products, and the application title B. An add...

  • Modify the JavaFX TipCalculator application program to allow the user to enter the number of persons...

    Modify the JavaFX TipCalculator application program to allow the user to enter the number of persons in the party through a text field. Calculate and display the amount owed by each person in the party if the bill is to be split evenly among the party members. /////////// TipCalculatorController.java: import java.math.BigDecimal; import java.math.RoundingMode; import java.text.NumberFormat; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Label; import javafx.scene.control.Slider; import javafx.scene.control.TextField; public class TipCalculatorController { // formatters for currency and percentages private...

  • You are to write a program (BookExceptionsDemo.java) that will create and, using user input, populate an...

    You are to write a program (BookExceptionsDemo.java) that will create and, using user input, populate an array of instances of the class Book. The class Book is loaded in our Canvas files: Book.java The user will enter a number n (n must be > 0, trap the user until they input a valid value for n), Your program will declare and create an array of size n of instances of the class Book. The user will be asked to enter...

  • please help me debug this Create a Future Value Calculator that displays error messages in labels.GUISpecificationsStart...

    please help me debug this Create a Future Value Calculator that displays error messages in labels.GUISpecificationsStart with the JavaFX version of the Future Value application presented in chapter 17. Create error message labels for each text field that accepts user input. Use the Validation class from chapter 17 to validate user input.Format the application so that the controls don’t change position when error messages are displayed. package murach.business; public class Calculation {        public static final int MONTHS_IN_YEAR =...

  • I need to make javafx GUI application called Email that implements a prototype user interface for...

    I need to make javafx GUI application called Email that implements a prototype user interface for composing email message. The application should have labelled text fields for To, cc,bcc ,subject line, one for message body and button lebelled Send. When we click Send button, the program should print contents of all fields to standard output using println() statement. I am attaching photos of Email.java and EmailPane.java, I need to make it as per these classes CylinderSta.. Cylinder java MultiCylind.. ....

  • eclipse java Oxygen Design a self-service fast food menu. Name your class FastFood. Create a test...

    eclipse java Oxygen Design a self-service fast food menu. Name your class FastFood. Create a test class based on the examples from chapter 4. Create a program to do the following. When you set up the program, save the java file to a folder named Chapter 04 Program. Console Welcome to the fast food order menu How may I help you Please place your order: НННН Please place your order Your order Your subtotal: $e.00 $e.00 Continue? (y/n): Y Please...

  • C# Temp. Converter program. Create a Celsius and Fahrenheit Temperature Converter application. The application must have...

    C# Temp. Converter program. Create a Celsius and Fahrenheit Temperature Converter application. The application must have 2 Labels (each one of them assigned only to Celsius and Fahrenheit), 2 TextBoxes (each one of them assigned only to Celsius and Fahrenheit), only 1 Convert Button, 1 Clear Button, and 1 Exit Button. Also, 1 Error message label which will display the error messages. The application should only allow the user to enter the desired temperature just in one of the TextBoxes...

  • Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters...

    Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...

  • PROGRAM STATEMENT AND REQUIREMENTS: Great Tutors Inc. is a company that provides tutoring services to elementary...

    PROGRAM STATEMENT AND REQUIREMENTS: Great Tutors Inc. is a company that provides tutoring services to elementary school students. Parents bring their students after school to their offices where one tutor is assigned to each student. The same tutor is assigned to the student for every visit. A tutor teaches his/her assigned student for several hours and charges a flat rate per hour for any student. Each tutor can only teach for a maximum of 40 hours. The program must ask...

  • There are a sotall of five classes and one enum required for this project. Over the...

    There are a sotall of five classes and one enum required for this project. Over the course of the projeet, it is important that you pay attention to how different responsibilities are separaled between the classes and how they work in coejuncticn to handle a probiem A quick list of the necessary items for this peogram are HotelManagement Class This is the driver class foe your peogram It will cntain a methed for setting up an initial hotel and the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT