Question

In: Computer Science

Hello, I am using IntelliJ IDEA with JavaFX to build a travel expensive calculator, but I...

Hello, I am using IntelliJ IDEA with JavaFX to build a travel expensive calculator, but I dont konw how to conver user input to doulbe. Pleasse teach me how to add all textfield and display it after I click submit.
public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{

        Label label1 = new Label ("(1) Number of days on the trip");
        Label label2 = new Label ("(2) Transportation cost (choose one only)");
        Label label3 = new Label ("Airfare Cost ");
        Label label4 = new Label ("Miles driven  ");
        Label label5 = new Label ("(3) Conference registration cost ");
        Label label6 = new Label ("(4) Lodging Cost (per night) ");
        Label label7 = new Label ("(5) Food cost (total) ");
        Label label8 = new Label ("(6) Lodging Cost (per night) ");
        Label TotalExpensive = new Label("Total expenses: ");
        Label TotalExpensiveResult = new Label(" ");



        TextField field1 = new TextField();
        TextField field2 = new TextField();
        TextField field3 = new TextField();
        TextField field4 = new TextField();
        TextField field5 = new TextField();
        TextField field6 = new TextField();
        TextField field7 = new TextField();


        Button button1 = new Button ("Submit"); //Create submit button
        Button button2 = new Button ("Cancel"); //Create Cancel button

        HBox hBox = new HBox(20, label1, field1);
        HBox hBox1 = new HBox(10, label2);
        HBox hBox2 = new HBox(15, label3, field2);
        HBox hBox3 = new HBox(10, label4, field3);
        HBox hBox4 = new HBox(12, label5, field4);
        HBox hBox5 = new HBox(32, label6, field5);
        HBox hBox6 = new HBox(75, label7, field6);
        HBox hBox7 = new HBox(32, label8, field7);
        HBox hBox8 = new HBox(20, button1, button2);
        HBox hBox9 = new HBox(20, TotalExpensive, TotalExpensiveResult);


        hBox.setAlignment(Pos.BASELINE_RIGHT);
        hBox1.setAlignment(Pos.BASELINE_LEFT);
        hBox2.setAlignment(Pos.BASELINE_RIGHT);
        hBox3.setAlignment(Pos.BASELINE_RIGHT);
        hBox4.setAlignment(Pos.BASELINE_RIGHT);
        hBox5.setAlignment(Pos.BASELINE_RIGHT);
        hBox6.setAlignment(Pos.BASELINE_RIGHT);
        hBox7.setAlignment(Pos.BASELINE_RIGHT);
        hBox8.setAlignment(Pos.CENTER);
        hBox9.setAlignment(Pos.CENTER);

        hBox.setPadding(new Insets(0,0,15,0));
        hBox3.setPadding(new Insets(0,0,15,0));
        hBox8.setPadding(new Insets(25,0,15,0));



        GridPane gridPane = new GridPane ();

        gridPane.add(hBox, 0, 0);
        gridPane.add(hBox1, 0, 1);
        gridPane.add(hBox2, 0, 2);
        gridPane.add(hBox3, 0, 3);
        gridPane.add(hBox4, 0, 4);
        gridPane.add(hBox5, 0, 5);
        gridPane.add(hBox6, 0, 6);
        gridPane.add(hBox7, 0, 7);
        gridPane.add(hBox8, 0, 8);
        gridPane.add(hBox9, 0, 9);

        //*******Here*********
        button1.setOnAction(event -> {
            double cost = field1;
            TotalExpensiveResult.setText("Total Cost: $" + cost);
        });




        gridPane.setAlignment(Pos.CENTER);
        gridPane.setPadding( new Insets(20, 20, 20, 20));
        gridPane.setVgap( 10);
        gridPane.setHgap( 10);

        primaryStage.setTitle("Travel Expenses Calculator");
        primaryStage.setScene(new Scene (gridPane));
        primaryStage.show();


    }

Solutions

Expert Solution

CODE

import javafx.application.Application;

import javafx.geometry.Insets;

import javafx.geometry.Pos;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.control.Label;

import javafx.scene.control.TextField;

import javafx.scene.layout.GridPane;

import javafx.scene.layout.HBox;

import javafx.stage.Stage;

public class Main extends Application {

@Override

public void start(Stage primaryStage) throws Exception{

Label label1 = new Label ("(1) Number of days on the trip");

Label label2 = new Label ("(2) Transportation cost (choose one only)");

Label label3 = new Label ("Airfare Cost ");

Label label4 = new Label ("Miles driven ");

Label label5 = new Label ("(3) Conference registration cost ");

Label label6 = new Label ("(4) Lodging Cost (per night) ");

Label label7 = new Label ("(5) Food cost (total) ");

Label label8 = new Label ("(6) Lodging Cost (per night) ");

Label TotalExpensive = new Label("Total expenses: ");

Label TotalExpensiveResult = new Label(" ");

TextField field1 = new TextField();

TextField field2 = new TextField();

TextField field3 = new TextField();

TextField field4 = new TextField();

TextField field5 = new TextField();

TextField field6 = new TextField();

TextField field7 = new TextField();

Button button1 = new Button ("Submit"); //Create submit button

Button button2 = new Button ("Cancel"); //Create Cancel button

HBox hBox = new HBox(20, label1, field1);

HBox hBox1 = new HBox(10, label2);

HBox hBox2 = new HBox(15, label3, field2);

HBox hBox3 = new HBox(10, label4, field3);

HBox hBox4 = new HBox(12, label5, field4);

HBox hBox5 = new HBox(32, label6, field5);

HBox hBox6 = new HBox(75, label7, field6);

HBox hBox7 = new HBox(32, label8, field7);

HBox hBox8 = new HBox(20, button1, button2);

HBox hBox9 = new HBox(20, TotalExpensive, TotalExpensiveResult);

hBox.setAlignment(Pos.BASELINE_RIGHT);

hBox1.setAlignment(Pos.BASELINE_LEFT);

hBox2.setAlignment(Pos.BASELINE_RIGHT);

hBox3.setAlignment(Pos.BASELINE_RIGHT);

hBox4.setAlignment(Pos.BASELINE_RIGHT);

hBox5.setAlignment(Pos.BASELINE_RIGHT);

hBox6.setAlignment(Pos.BASELINE_RIGHT);

hBox7.setAlignment(Pos.BASELINE_RIGHT);

hBox8.setAlignment(Pos.CENTER);

hBox9.setAlignment(Pos.CENTER);

hBox.setPadding(new Insets(0,0,15,0));

hBox3.setPadding(new Insets(0,0,15,0));

hBox8.setPadding(new Insets(25,0,15,0));

GridPane gridPane = new GridPane ();

gridPane.add(hBox, 0, 0);

gridPane.add(hBox1, 0, 1);

gridPane.add(hBox2, 0, 2);

gridPane.add(hBox3, 0, 3);

gridPane.add(hBox4, 0, 4);

gridPane.add(hBox5, 0, 5);

gridPane.add(hBox6, 0, 6);

gridPane.add(hBox7, 0, 7);

gridPane.add(hBox8, 0, 8);

gridPane.add(hBox9, 0, 9);

//*******Here*********

button1.setOnAction(event -> {

double cost = Double.parseDouble(field1.getText());

TotalExpensiveResult.setText("Total Cost: $" + cost);

});

gridPane.setAlignment(Pos.CENTER);

gridPane.setPadding( new Insets(20, 20, 20, 20));

gridPane.setVgap( 10);

gridPane.setHgap( 10);

primaryStage.setTitle("Travel Expenses Calculator");

primaryStage.setScene(new Scene(gridPane));

primaryStage.show();

}

}


Related Solutions

I am using IntelliJ IDEA with JavaFX to build a travel expensive calculator, but somehow it...
I am using IntelliJ IDEA with JavaFX to build a travel expensive calculator, but somehow it wouldn't calculate total expensive? It was working until I add the TextFieldListener because I need to make sure user only input either mile driven or airfareCost. Please help me figure out what I did wrong. import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.event.EventHandler; import javafx.fxml.FXMLLoader; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import...
Using the BAII Plus calculator I am having a difficult time using this calculator to solve...
Using the BAII Plus calculator I am having a difficult time using this calculator to solve this MIRR 0 =-325,000 1=50,000 2= 75,000 3=-60,000 4=225,000 5=300,000 Required rate of return =15% We discount all negative CFs(at 15%) time 0 We compound all positive cash flows (at 15%) to 5 years This is now the TV or Terminal Value Please help me understand how to calculate these numbers?
Using the IntelliJ IDEA tool, write a program that will print a Christmas tree with the...
Using the IntelliJ IDEA tool, write a program that will print a Christmas tree with the "*". The tree should have at least 10 lines. Look back at the birthday cake lab for examples of how to do this lab. Submit a screen shot of your output in the console (i.e. non REPL tool).
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
Hello, i am currently working on an attendance system using MATLAB by the comparison of 2...
Hello, i am currently working on an attendance system using MATLAB by the comparison of 2 images of the same class, does anyone have any ideas or methods to use
Hello, I am studying and I am a bit confused about registers. There are segments registers,...
Hello, I am studying and I am a bit confused about registers. There are segments registers, data registers, pointer registers, index registers. But I do not really understand where these are found. Are they found in 8086 architecture? For instance if I ask what type of registers are found in 8086 architecture what will be the answer? All of these or only segment registers?
how to prepare a proposal for your business idea? if i am taking a idea to...
how to prepare a proposal for your business idea? if i am taking a idea to open a restaurant entreprenurship
Java ArrayList Parking Ticket Simulator, Hello I am stuck on this problem where I am asked...
Java ArrayList Parking Ticket Simulator, Hello I am stuck on this problem where I am asked to calculate the sum of all fines in the policeOfficer class from the arraylist i created. I modified the issueParking ticket method which i bolded at the very end to add each issued Parking ticket to the arrayList, i think thats the right way? if not please let me know. What I dont understand how to do is access the fineAmountInCAD from the arrayList...
.Suppose I am in a boat and I travel at the bearing N70E at 30 knots...
.Suppose I am in a boat and I travel at the bearing N70E at 30 knots for 4 hours. Then, I turn 90 degrees clockwise and travel for 5 hours at the same speed. Find my bearing relative to the dock.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT