Question

In: Computer Science

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

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 extend GridPane. The only inctance 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
  • 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.
  • After entering 777, the program is the returning the largest whole number of yards which is 21. (Two yards take only 21 * 36 = 756 inches)

    From the remainder (777 -756  which is 21) program determines the largest whole number of feet. In 21 inches there are 1 feet. (Two feet take only 2 *12 = 24 inches, only one group of 12 fits)

    So 21-12 is 9 and that's how you find the remaining inches.

    So for input of inches the program should return  2 yards, 2 feet, and 2 inches.

    Follow these conversion facts:

    1 yard has 36 inches.

    1 foot has 12 inches.

Solutions

Expert Solution

Working code implemented in 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:

Sample Output Screenshots:

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


Related Solutions

In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle's radius....
In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle's radius. A respective square whose diagonal is the circle's diameter can then be created. There are three other controls in this application: a button(btCalculate), two textareas(trCircleArea, trSquareArea). When the button is clicked, the circle's area is calculated and displayed on trCircleArea, furthermore, the square's area is also calculated and displayed on trSquareArea. Please write portions of codes which calculates the circle's area and the square's...
Java In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle’s...
Java In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle’s radius. A respective square whose diagonal is the circle's diameter can then be created. There are three other controls in this application: a button(btCalculate), two textareas(trCircleArea, trSquareArea). When the button is clicked, the circle's area is calculated and displayed on trCircleArea, furthermore, the square's area is also calculated and displayed on trSquareArea. Please write the portions of codes which calculates the circle’s area and...
In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle’s radius....
In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle’s radius. A respective square whose diagonal is the circle's diameter can then be created. There are three other controls in this application: a button(btCalculate), two textareas(trCircleArea, trSquareArea). When the button is clicked, the circle's area is calculated and displayed on trCircleArea, furthermore, the square's area is also calculated and displayed on trSquareArea. Please write the portions of codes which calculates the circle’s area and the...
Create a JavaFX application that lets the user enter the food charge for a meal at...
Create a JavaFX application that lets the user enter the food charge for a meal at a restaurant. For example, if $20 is entered as a food charge for a meal then $3.6 should be displayed for the tip, $1.4 should be displayed for sales tax, and $25 should be displayed as a total of all three amounts. Modification 1: create a text box (not a pop up) for the user to enter a percent tip (don't just hardcode it...
This lab is designed to design an event driven animation application which JavaFX application implementing a...
This lab is designed to design an event driven animation application which JavaFX application implementing a racing car image. The car moves from left to right. When it hits the right end, it restarts from the left and continues the same process. Let the user pause/resume the animation with a button press/release and increase/decrease the car speed by pressing the up and down arrow keys. The car used for this application has the following attributes. Task(s) Task 1: Create a...
Develop a JavaFX GUI application called Registration that implements a user interface for registering for a...
Develop a JavaFX GUI application called Registration that implements a user interface for registering for a web site. The application should have labeled text fields for the Full Name, User Name, Password, Student Id, and a TextAreafor About Me. Include a button labeled Send. When the Send button is clicked, your program should print the contents of all fields (with labels) to standard output using println()statements.
Write a JavaFX application that presents two buttons and a number (initially 50) to the user....
Write a JavaFX application that presents two buttons and a number (initially 50) to the user. Label the buttons Increment and Decrement. When the increment button is pushed, increment the displayed value. Likewise, decrement the value when the decrement button is pushed. This has to use Java.Fx and not Java.Awt
Write application in C# that enables a user to: Use Methods for user input and calculations...
Write application in C# that enables a user to: Use Methods for user input and calculations input the grade and number of credit hours for any number of courses. Calculate the GPA on a 4.0 scale using those values. Grade point average (GPA) is calculated by dividing the total amount of grade points earned, sometimes referred to as quality points, by the total number of credit hours attempted. For each hour, an A receives 4 grade or quality points, a...
Write an application that accepts up to 20 Strings, or fewer if the user enters the...
Write an application that accepts up to 20 Strings, or fewer if the user enters the terminating value ZZZ. Store each String in one of two lists—one list for short Strings that are 10 characters or fewer and another list for long Strings that are 11 characters or more. After data entry is complete, prompt the user to enter which type of String to display, and then output the correct list. For this exercise, you can assume that if the...
Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT