Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is my javafx code. Is it javafx? I can't run this code. what is wrong? import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.HPos; import
This is my javafx code. Is it javafx?
I can't run this code.
what is wrong?
import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.HPos; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.GridPane; import javafx.scene.layout.Priority; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.stage.Stage; public class TravelExpenses extends Application { private Label daysLabel; private Label airfareLabel; private Label carLabel; private Label milesLabel; private Label parkingLabel; private Label taxiLabel; private Label seminarLabel; private Label lodgeLabel; private Label meals; private Label parking; private Label taxi; private Label lodge; private Label mile; private TextField daysTextField; private TextField airfareTextField; private TextField carTextField; private TextField milesTextField; private TextField parkingTextField; private TextField taxiTextField; private TextField seminarTextField; private TextField lodgeTextField; private Button calculations; private final double MEALS_PER_DAY = 37.00; private final double PARKING_PER_DAY = 10.00; private final double TAXT_PER_DAY = 20.00; private final double LODGING_PER_DAY = 95.00; private final double D_PER_MILE = 0.27; public static void main(String[] args) { launch(); } @Override public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Travel Expences"); Font font = Font.font("Arial", FontWeight.BOLD, 12); GridPane gridPane = createRegistrationFormPane(); createLabels(font); createInputFields(); calculations = new Button("Display the details"); calculations.setOnAction(e -> calculate()); calculations.setFont(font); addElements(gridPane); Scene scene = new Scene(gridPane, 280, 500); primaryStage.setScene(scene); primaryStage.show(); } private void createLabels(Font font) { daysLabel = new Label("Number of Days: "); airfareLabel = new Label("Amount of airfare: $"); carLabel = new Label("Car rental fees: $"); milesLabel = new Label("Number of miles: "); parkingLabel = new Label("Parinkg fees: $"); taxiLabel = new Label("Taxi charges: $"); seminarLabel = new Label("Seminar fees: $"); lodgeLabel = new Label("Lodging fees per night: $"); meals = new Label("Meals per day: $" + MEALS_PER_DAY); parking = new Label("Parking fee per day: $" + PARKING_PER_DAY); taxi = new Label("Taxi charges per day: $" + TAXT_PER_DAY); lodge = new Label("Lodging charges per day: $" + LODGING_PER_DAY); mile = new Label("Chargers per mile: $" + D_PER_MILE); } private void createInputFields() { daysTextField = new TextField(); carTextField = new TextField(); milesTextField = new TextField(); parkingTextField = new TextField(); taxiTextField = new TextField(); seminarTextField = new TextField(); lodgeTextField = new TextField(); } private void addElements(GridPane gridPane) { gridPane.add(daysLabel, 0,0,2,1); gridPane.add(daysTextField, 0, 1, 2, 1); gridPane.add(airfareLabel, 0,2,2,1); gridPane.add(airfareTextField, 0, 3, 2, 1); gridPane.add(carLabel, 0, 4, 2, 1); gridPane.add(carTextField, 0, 5, 2, 1); gridPane.add(milesLabel, 0, 8, 2, 1); gridPane.add(milesTextField, 0, 9, 2, 1); gridPane.add(parkingLabel, 0, 10, 2, 1); gridPane.add(parkingTextField, 0, 11, 2, 1); gridPane.add(taxiLabel, 0, 12, 2, 1); gridPane.add(taxiTextField, 0, 13, 2, 1); gridPane.add(seminarLabel, 0, 14, 2, 1); gridPane.add(seminarTextField, 0, 15, 2, 1); gridPane.add(lodgeLabel, 0, 16, 2, 1); gridPane.add(lodgeTextField, 0, 17, 2, 1); gridPane.add(calculations, 1, 24, 1, 1); gridPane.add(meals,1,25,1,1); gridPane.add(parking,1,25,1,1); gridPane.add(taxi,1,25,1,1); gridPane.add(lodge,1,25,1,1); gridPane.add(mile,1,25,1,1); gridPane.add(calculations,1,25,1,1); calculations.setPrefWidth(200); calculations.setMinWidth(200); calculations.setAlignment(Pos.CENTER); } private GridPane createRegistrationFormPane() { GridPane gridPane = new GridPane(); gridPane.setAlignment(Pos.CENTER); gridPane.setPadding(new Insets(20)); gridPane.setHgap(20); gridPane.setVgap(5); ColumnConstraints columnOneConstraints = new ColumnConstraints(140, 140, Double.MAX_VALUE); columnOneConstraints.setHalignment(HPos.CENTER); ColumnConstraints columnTwoConstrains = new ColumnConstraints(60,60, Double.MAX_VALUE); columnTwoConstrains.setHgrow(Priority.ALWAYS); columnTwoConstrains.setHalignment(HPos.RIGHT); gridPane.getColumnConstraints().addAll(columnOneConstraints, columnTwoConstrains); return gridPane; } private void calculate() { double totalExpences; double allowedExpences; double days = Integer.parseInt(daysTextField.getText()); double d1 = Double.parseDouble(airfareTextField.getText()); double d2 = Double.parseDouble(carTextField.getText()); double d3 = Double.parseDouble(milesTextField.getText()); double d4 = Double.parseDouble(parkingTextField.getText()); double d5 = Double.parseDouble(taxiTextField.getText()); double d6 = Double.parseDouble(seminarTextField.getText()); double d7 = Double.parseDouble(lodgeTextField.getText()); totalExpences = d1 + d2 + (d3 * D_PER_MILE) + d4 + d5 + d6 + (d7 * days); allowedExpences = (MEALS_PER_DAY + PARKING_PER_DAY + TAXT_PER_DAY + LODGING_PER_DAY) * days + (d3 * D_PER_MILE); alert(String.format("Total expenses by business person: $%s " + "Allowable expenses for the trip: $%s Amount saved by the business person: $%s")); } private void alert(String text) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Message"); alert.setHeaderText(null); alert.setContentText(text); alert.getDialogPane().setPrefWidth(300); alert.showAndWait(); } }
This is my output.
Output Travel Expences Number of Days: 3 Amount of airfare: $ 200 Car rental fees: $ 100 Number of miles: 300 Parking tees:s 15 Lodging tees per night:s 20 Meals per day: $37.0 Parking fee per day: $10.0 Taxi charges per day $20.0 Lodging charges per day $95.0 Chargers per Message iTotal expenses ty business person: $566.0 Alowalble expenses for the trip: $567.0 Amount saved by the business person: $1.0 OK Type here to search US 10/30/2017Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started