Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have done the first part of creating the GUI now i need u to add this to my code . here is my code

I have done the first part of creating the GUI now i need u to add this to my code .

image text in transcribed

here is my code of the GUI

package application;

import java.util.ArrayList;

import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.scene.paint.Color; import javafx.stage.Stage;

public class Driver extends Application { ArrayList orders = new ArrayList();

private String customerName = ""; private String orderType = "ToGo"; private int pizzaSize = 1; private boolean onionTopping = false; private boolean oliveTopping = false; private boolean greenPepperTopping = false; private double toppingPrice = 10.0; private double orderPrice = 0.0; private double tripRate = 0.0; private int zone = 0; private double serviceCharge = 0.0; private int numberOfPeople = 0;

public static void main(String[] args) { launch(args); }

@Override public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Pizza Order");

BorderPane borderPane = new BorderPane(); borderPane.setPadding(new Insets(10, 10, 10, 10));

// create the labels and fields for customer name, order type, pizza size, and toppings Label customerNameLabel = new Label("Customer Name:"); TextField customerNameField = new TextField(); Label orderTypeLabel = new Label("Order Type:"); ToggleGroup orderTypeGroup = new ToggleGroup(); RadioButton togoButton = new RadioButton("ToGo"); togoButton.setToggleGroup(orderTypeGroup); togoButton.setSelected(true); RadioButton deliveryButton = new RadioButton("Delivery"); deliveryButton.setToggleGroup(orderTypeGroup); RadioButton seatedButton = new RadioButton("Seated"); seatedButton.setToggleGroup(orderTypeGroup); Label pizzaSizeLabel = new Label("Pizza Size:"); ComboBox pizzaSizeComboBox = new ComboBox(); pizzaSizeComboBox.getItems().addAll("Small", "Medium", "Large"); pizzaSizeComboBox.setValue("Small"); Label toppingsLabel = new Label("Toppings:"); CheckBox onionToppingCheckBox = new CheckBox("Onions"); CheckBox oliveToppingCheckBox = new CheckBox("Olives"); CheckBox greenPepperToppingCheckBox = new CheckBox("Green Peppers"); Label toppingPriceLabel = new Label("Topping Price:"); TextField toppingPriceField = new TextField(); toppingPriceField.setText(String.valueOf(toppingPrice));

// create the gridpane for the labels and fields GridPane gridPane = new GridPane(); gridPane.setHgap(10); gridPane.setVgap(10); gridPane.add(customerNameLabel, 0, 0); gridPane.add(customerNameField, 1, 0); gridPane.add(orderTypeLabel, 0, 1); gridPane.add(togoButton, 1, 1); gridPane.add(deliveryButton, 2, 1); gridPane.add(seatedButton, 3, 1); gridPane.add(pizzaSizeLabel, 0, 2); gridPane.add(pizzaSizeComboBox, 1, 2); gridPane.add(toppingsLabel, 0, 3); gridPane.add(onionToppingCheckBox, 1, 3); gridPane.add(oliveToppingCheckBox, 2, 3); gridPane.add(greenPepperToppingCheckBox, 3, 3); gridPane.add(toppingPriceLabel, 0, 4); gridPane.add(toppingPriceField, 1, 4); // create the labels and fields for trip rate and zone (for delivery) Label tripRateLabel = new Label("Trip Rate:"); TextField tripRateField = new TextField(); Label zoneLabel = new Label("Zone:"); TextField zoneField = new TextField(); // create the labels and fields for service charge and number of people (for seated) Label serviceChargeLabel = new Label("Service Charge:"); TextField serviceChargeField = new TextField(); Label numberOfPeopleLabel = new Label("Number of People:"); TextField numberOfPeopleField = new TextField();

// add the gridpane to the center of the borderpane borderPane.setCenter(gridPane); // create the process order, print orders, and reset buttons Button processOrderButton = new Button("Process Order"); Button printOrdersButton = new Button("Print Orders"); Button resetButton = new Button("Reset"); // create a hbox for the buttons HBox hBox = new HBox(); hBox.setSpacing(10); hBox.setPadding(new Insets(10, 10, 10, 10)); hBox.getChildren().addAll(processOrderButton, printOrdersButton, resetButton); // add the hbox to the bottom of the borderpane borderPane.setBottom(hBox); // show the GUI borderPane.setStyle("-fx-background-color: Gray;"); Scene scene = new Scene(borderPane, 500, 500); primaryStage.setScene(scene); primaryStage.show(); // add an event handler for the delivery radio button deliveryButton.setOnAction(event -> { gridPane.getChildren().removeAll(serviceChargeLabel, serviceChargeField, numberOfPeopleLabel, numberOfPeopleField); gridPane.add(tripRateLabel, 0, 5); gridPane.add(tripRateField, 1, 5); gridPane.add(zoneLabel, 2, 5); gridPane.add(zoneField, 3, 5); }); // add an event handler for the seated radio button seatedButton.setOnAction(event -> { gridPane.getChildren().removeAll(tripRateLabel, tripRateField, zoneLabel, zoneField); gridPane.add(serviceChargeLabel, 0, 5); gridPane.add(serviceChargeField, 1, 5); gridPane.add(numberOfPeopleLabel, 2, 5); gridPane.add(numberOfPeopleField, 3, 5); }); togoButton.setOnAction(event ->{ gridPane.getChildren().removeAll(serviceChargeLabel, serviceChargeField, numberOfPeopleLabel, numberOfPeopleField,tripRateLabel, tripRateField, zoneLabel, zoneField); }); } } and here is the constructors for Classes ToGo and Seated and Delivery and PizzaOrder

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

After the user fills the form and presses the button Processorder your program should do the following: - Your program should create an appropriate object based on the pizza order type selected ( ToGo, Delivery, or Seated) using the data provided by the user in the GUI. - Add the created pizza order object to an ArrayList of type PizzaOrder called orders. - Use the created object to calculate the orderPrice and display it to the GUI. - You do NOT need to check for valid text field inputs (double, int, ...). You may assume that the user enters valid data for each of the text fields. Pressing the button labeled Printorders should sort and print a list of custom er names and order prices for orders saved in ArrayList orders to a separate stage ( different from the original GUI ). Pressing the Reset button should reset ALL items and fields to their default values as specified above as well as remove all the orders from the ArrayList orders. public ToGo(String customerName, int pizzaSize, int numberofToppings, double toppingPrice) \{ super(customerName, pizzaSize, numberofToppings, toppingPrice); public Seated(String customerName, int pizzaSize, int numberOfToppings, double toppingPrice, double serviceCharge, int numberOfPeople) \{ super(customerName, pizzaSize, numberOfToppings, toppingPrice); this.serviceCharge = serviceCharge; this.numberofPeople = numberOfPeople; public PizzaOrder (String customerName, int pizzaSize, int numberofToppings, double toppingPrice) \{ this.customerName = customerName; this.dateOrdered = new Date(); this.pizzaSize = pizzaSize; this.numberofToppings = numberofToppings; this.toppingPrice = toppingPrice

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

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions

Question

Prepare a constructive performance appraisal.

Answered: 1 week ago

Question

List the advantages of correct report formatting.

Answered: 1 week ago