Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Why am I getting a cannot be resolved error on my code? package application; import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control. * ; import

Why am I getting a cannot be resolved error on my code?
package application;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class RoadTripCostEstimator extends Application {
public static void main(String[] args){
Application.launch(args);
}
@Override
public void start(Stage primaryStage){
primaryStage.setTitle("Road Trip Cost Estimator");
GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(10,10,10,10));
Label distanceLabel = new Label("Distance:");
TextField distanceField = new TextField();
ComboBox distanceUnitCombo = new ComboBox>();
distanceUnitCombo.getItems().addAll("Miles", "Kilometers");
Label gasolineCostLabel = new Label("Gasoline Cost:");
TextField gasolineCostField = new TextField();
ComboBox gasolineCostUnitCombo = new ComboBox>();
gasolineCostUnitCombo.getItems().addAll("Dollars/Gal", "Dollars/Liter");
Label gasMileageLabel = new Label("Gas Mileage:");
TextField gasMileageField = new TextField();
ComboBox gasMileageUnitCombo = new ComboBox>();
gasMileageUnitCombo.getItems().addAll("Miles/Gal","Km/Liter");
Label numberOfDaysLabel = new Label("Number of Days:");
TextField numberOfDaysField = new TextField();
Label hotelCostLabel = new Label("Hotel Cost per Day:");
TextField hotelCostField = new TextField();
Label foodCostLabel = new Label("Food Cost per Day:");
TextField foodCostField = new TextField();
Label attractionsCostLabel = new Label("Attractions Cost:");
TextField attractionsCostField = new TextField();
Button calculateButton = new Button("Calculate");
Label resultLabel = new Label("Total Trip Cost:");
TextField resultField = new TextField();
resultField.setEditable(false);
grid.add(distanceLabel,0,0);
grid.add(distanceField,1,0);
grid.add(distanceUnitCombo,2,0);
grid.add(gasolineCostLabel,0,1);
grid.add(gasolineCostField,1,1);
grid.add(gasolineCostUnitCombo,2,1);
grid.add(gasMileageLabel,0,2);
grid.add(gasMileageField,1,2);
grid.add(gasMileageUnitCombo,2,2);
grid.add(numberOfDaysLabel,0,3);
grid.add(numberOfDaysField,1,3);
grid.add(hotelCostLabel,0,4);
grid.add(hotelCostField,1,4);
grid.add(foodCostLabel,0,5);
grid.add(foodCostField,1,5);
grid.add(attractionsCostLabel,0,6);
grid.add(attractionsCostField,1,6);
grid.add(calculateButton,0,7);
grid.add(resultLabel,0,8);
grid.add(resultField,1,8);
calculateButton.setOnAction(e ->{
double distance = Double.parseDouble(distanceField.getText());
double gasolineCost = Double.parseDouble(gasolineCostField.getText());
double gasMileage = Double.parseDouble(gasMileageField.getText());
int numberOfDays = Integer.parseInt(numberOfDaysField.getText());
double hotelCost = Double.parseDouble(hotelCostField.getText());
double foodCost = Double.parseDouble(foodCostField.getText());
double attractionsCost = Double.parseDouble(attractionsCostField.getText());
double totalTripCost = calculateTotalTripCost(distance, gasolineCost, gasMileage, numberOfDays, hotelCost, foodCost, attractionsCost);
resultField.setText(String.format("%.2f", totalTripCost));
});
Scene scene = new Scene(grid,400,400);
primaryStage.setScene(scene);
primaryStage.show();
}
private double calculateTotalTripCost(double distance, double gasolineCost, double gasMileage, int numberOfDays, double hotelCost, double foodCost, double attractionsCost){
double gasolineCostInLiters =(distance *(distanceUnitCombo.getValue().equals("Miles")?1.60934 : 1))/(gasMileage *(gasMileageUnitCombo.getValue().equals("Miles per Gallon")?1 : 0.264172));
double totalTripCost =(gasolineCostInLiters *(gasolineCostUnitCombo.getValue().equals("Dollars per Gallon")?3.78541 : 0.264172)* gasolineCost)
+(hotelCost + foodCost)* numberOfDays + attractionsCost;
return totalTripCost;
}
}(hotelCost + foodCost)* numberofDays + attractionsCost;
return totaltripCost;
}
Exception in thread "JavaFx Application Thread" java.lang.Error: Unresolved compilation problems:
distanceUnitCombo cannot be resolved
gasMileageUnitCombo cannot be resolved
gasolineCostunitCombo cannot be resolved
at application.RoadTripCostEstimator.calculateTotalTripCost (RoadTripCostEstimator.java:101)
at application.RoadTripCostEstimator.lambda$$0
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Discuss how emotions affect our memory processing.

Answered: 1 week ago

Question

7. List behaviors to improve effective leadership in meetings

Answered: 1 week ago

Question

6. Explain the six-step group decision process

Answered: 1 week ago