我无法从我的组合框中选择一个小计。我正在创建一个餐馆应用程序,有人从组合框中选择一个项目,然后该项目被添加到列表框中。随着项目的添加,我试图将这些项目存储到数组列表中。然后获取该数组列表并将价格一起添加到小计中。我可以添加任何项目选择到数组。所以1项。我无法将项目总计为打印小计。有人可以帮我一把。我已经在这2天了,我将不胜感激任何帮助。先感谢您。
double bcost [] = { 1.95, 1.50, 1.25, 2.95, 2.50, 1.50 };
double acost [] = { 5.95, 6.95, 8.95, 8.95, 10.95, 12.95, 6.95 };
double mcost [] = { 15.95, 13.95, 13.95, 11.95, 19.95, 20.95, 18.95, 13.95, 14.95 };
double dcost [] = { 5.95, 3.95, 5.95, 4.95, 5.95 };
String [] beverages = { "Soda", "Tea", "Coffee", "Mineral Water", "Juice", "Milk" };
String [] appetizers = { "Buffalo Wings", "Buffalo Fingers", "Potato Skins", "Nachos", "Mushroom Caps",
"Shrimp Cocktail" };
String [] maincourse = { "Seafood Alfredo", "Chicken Alfredo", "Chicken Picatta", "Turkey Club", "Lobster Pie",
"Prime Rib", "Shrimp Scampi", "Turkey Dinner", "Stuffed Chicken" };
String [] dessert = { "Apple Pie", "Sundae", "Carrot Cake", "Mud Pie", "Apple Crisp" };
//-------------------------------------------------------------------------------
ComboBox<String> beverageComboBox = new ComboBox<String>();
ObservableList<String> items1 = FXCollections.observableArrayList(beverages);
beverageComboBox.getItems().addAll(items1);
Label bo = new Label("Beverage Ordered");
pane.add(bo, 2, 5);
ListView<String> list1 = new ListView<>();
beverageComboBox.setOnAction((e) -> {
list1.getItems().add(beverageComboBox.getSelectionModel().getSelectedItem());
});
list1.addEventHandler(MouseEvent.MOUSE_CLICKED, e -> {
list1.getItems().remove(list1.getSelectionModel().getSelectedIndex());
});
pane.add(list1, 3, 5);
GridPane.setRowSpan(list1, 5);
// --------------------------------------------------------------------------------------------------------------------
ComboBox<String> appetizerComboBox = new ComboBox<String>();
ObservableList<String> items2 = FXCollections.observableArrayList(appetizers);
appetizerComboBox.getItems().addAll(items2);
Label ao = new Label("Appetizer Ordered");
pane.add(ao, 2, 10);
ListView<String> list2 = new ListView<>();
appetizerComboBox.setOnKeyPressed((e) -> {
list2.getItems().add(appetizerComboBox.getSelectionModel().getSelectedItem());
});
list2.addEventHandler(MouseEvent.MOUSE_CLICKED, e -> {
list2.getItems().remove(list2.getSelectionModel().getSelectedIndex());
});
pane.add(list2, 3, 10);
GridPane.setRowSpan(list2, 5);
//-------------------------------------------------------------------------------
Button cal = new Button(" Calculate Bill ");
// Setting an action for the Calculate button btn.setOnAction(new
cal.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
double tax = 0.00;
double total = 0.00;
ArrayList<Double> cal = new ArrayList<Double>();
if (ActionEvent.getSource() == beverageComboBox) {
cal.add(bcost[beverageComboBox.getSelectionModel().getSelectedIndex()]);
double subtotal = 0;
for (Double price : cal) {
subtotal += price;
}
// subtotal = cal;
// tax = subtotal * .07;
// total = subtotal + tax;
tst.setText(Double.toString(subtotal));
tt.setText(Double.toString(tax));
tto.setText(Double.toString(total));
}
}
});
pane.add(cal, 3, 30);