Zookal
Zookal

We’d love to hear any feedback or comment from you!

© 2011-2021 Zookal Pty Ltd

View question and answer

From our collection of questions and answers
Engineering · Computer Science
Question details

Please provide the TipCaculatorController code based on the following TipCalculator main class and TipCalculator.fxml code.

Use JavaFX and scenebuilder.

TipCalculator.java

package application;   
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.fxml.FXMLLoader;
public class TipCalculator extends Application {
   @Override
   public void start(Stage primaryStage) {
       try {
           GridPane root = (GridPane)FXMLLoader.load(getClass().getResource("TipCalculator.fxml"));
           Scene scene = new Scene(root,400,400);
           scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
           primaryStage.setScene(scene); //attach scene to stage
           primaryStage.show(); //display the stage
       } catch(Exception e) {
           e.printStackTrace();
       }
public static void main(String[] args) {
       launch(args);
   }

}

TipCalculator.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import com.gluonhq.charm.glisten.control.AutoCompleteTextField?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>

<GridPane alignment="TOP_LEFT" hgap="8.0" vgap="0.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.TipCalculatorController">
<children>
<Label text="Purchase Amount" textAlignment="RIGHT" GridPane.columnIndex="0" GridPane.rowIndex="0" />
<Label text="15%" textAlignment="RIGHT" GridPane.rowIndex="2" />
<Label fx:id="tipPercentageLabel" text="Additional Tip" textAlignment="RIGHT" GridPane.rowIndex="3" />
<Label text="Total" textAlignment="RIGHT" GridPane.rowIndex="4" />
<Label textAlignment="RIGHT" GridPane.rowIndex="5" />
<TextField id="amountTextBox" fx:id="amountTextField" prefWidth="-1.0" GridPane.columnIndex="1" GridPane.rowIndex="0" />
<Slider fx:id="tipPercentageSlider" blockIncrement="5.0" majorTickUnit="1.0" max="30.0" minorTickCount="1" showTickLabels="false" showTickMarks="false" snapToTicks="true" value="15.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField fx:id="tipTextField" editable="false" focusTraversable="false" prefWidth="-1.0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<TextField fx:id="totalTextField" editable="false" focusTraversable="false" prefWidth="-1.0" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Button id="calculateButton" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#calculateButtonPressed" text="Calculate" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<AutoCompleteTextField prefHeight="38.0" prefWidth="149.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="Billed Tipped Amount" GridPane.rowIndex="1" />
</children>
<columnConstraints>
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES" minWidth="10.0" prefWidth="-1.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="-1.0" />
</columnConstraints>
<padding>
<Insets bottom="14.0" left="14.0" right="14.0" top="14.0" />
</padding>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>

Output

Tip Calculator 3 Tip Calculator 3 Tip Calculator Purchase Amount 100.00 Purchase Amount 100.00 Purchase Amount 100.00 Billed Tip Amount 000 Billed Tip Amount 10.00 Billed Tip Amount 10.00 15% 15% Minimum 10% Additional Tip $15.00 Additional Tip $5.00 Additional Tip $0.00 Total $115.00 Total $115.00 Total $110.00 Calculate Calculate Calculate Example1 Example 2 Example3






























































  

Answer
Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.

Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.