Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am making a GUI application on pizza Shop menu. it asks for name of customer and type of pizza as well as size of

I am making a GUI application on pizza Shop menu. it asks for name of customer and type of pizza as well as size of pizza. I did everything but i am not able to do the price part. Below is the screenshot of the price list. For regular pizza we can not check more than 2 toppings for the checkbox(i dont know how to do that) and no more that 3 toppings in feast. We have to display the total cost in scene 1(according to the code written below).

package application;

import javafx.application.Application;

import javafx.event.ActionEvent;

import javafx.event.EventHandler;

import javafx.geometry.Pos;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.control.CheckBox;

import javafx.scene.control.Hyperlink;

import javafx.scene.control.Label;

import javafx.scene.control.RadioButton;

import javafx.scene.control.TextField;

import javafx.scene.control.ToggleGroup;

import javafx.scene.image.Image;

import javafx.scene.image.ImageView;

import javafx.scene.layout.GridPane;

import javafx.scene.layout.HBox;

import javafx.scene.layout.VBox;

import javafx.scene.text.Font;

import javafx.stage.Stage;

public class Main extends Application {

@Override

public void start(Stage primaryStage) {

GridPane root = new GridPane();

root.setAlignment(Pos.CENTER);

root.setHgap(10);

root.setVgap(10);

Scene scene = new Scene(root,600,600);

Label title = new Label("Enter Details");

root.add(title, 0, 0, 2, 1);

title.setFont(Font.font(60));

TextField firstNameFld = new TextField();

TextField lastNameFld = new TextField();

Label firstNameLb1 = new Label("First Name: ");

Label lastNameLb1 = new Label("Last Name: ");

firstNameLb1.setLabelFor(firstNameFld);

lastNameLb1.setLabelFor(lastNameFld);

firstNameLb1.setMnemonicParsing(true);

lastNameLb1.setMnemonicParsing(true);

root.addRow(1, firstNameLb1, firstNameFld);

root.addRow(2, lastNameLb1, lastNameFld);

Button btn = new Button("Order Details");

root.add(btn, 0,14);

Label title1 = new Label("Choose the type of pizza you want");

root.add(title1, 0,3);

title1.setStyle("-fx-font-weight: bold;");

RadioButton radiobutton4 = new RadioButton("Regular");

RadioButton radiobutton5 = new RadioButton("Feast");

ToggleGroup radioGroup1 = new ToggleGroup();

radiobutton4.setToggleGroup(radioGroup1);

radiobutton5.setToggleGroup(radioGroup1);

VBox vbox1 = new VBox(radiobutton4, radiobutton5 );

root.add(vbox1, 0, 5, 2, 1 );

Label title2 = new Label("Choose the size of pizza you want");

root.add(title2, 0,7);

title2.setStyle("-fx-font-weight: bold;");

RadioButton radioButton1 = new RadioButton("small");

RadioButton radioButton2 = new RadioButton("medium");

RadioButton radioButton3 = new RadioButton("large");

ToggleGroup radioGroup = new ToggleGroup();

radioButton1.setToggleGroup(radioGroup);

radioButton2.setToggleGroup(radioGroup);

radioButton3.setToggleGroup(radioGroup);

VBox vbox2 = new VBox(radioButton1, radioButton2, radioButton3);

root.add(vbox2, 0, 8, 3, 2 );

Label title4 = new Label("Choose the toppings you would like to have on the pizza ");

root.add(title4, 0,10);

title4.setStyle("-fx-font-weight: bold;");

CheckBox cb1 = new CheckBox("Chicken");

CheckBox cb2 = new CheckBox("peppers");

CheckBox cb3 = new CheckBox("mushrooms");

HBox hbox = new HBox(cb1,cb2,cb3);

root.add(hbox, 0, 12, 2, 1 );

GridPane root2 = new GridPane();

root2.setAlignment(Pos.CENTER);

root2.setHgap(10);

root2.setVgap(10);

Scene scene1 = new Scene(root2,600,600);

Label outRadioBtn1 = new Label();

root2.add(outRadioBtn1, 0, 2);

Label outRadioBtn2 = new Label();

root2.add(outRadioBtn2, 0, 3);

Label nameLabel = new Label();

root2.add(nameLabel, 0, 1);

Label cbOut = new Label();

root2.add(cbOut, 0, 4);

GridPane root3 = new GridPane();

root3.setAlignment(Pos.CENTER);

root3.setHgap(10);

root3.setVgap(10);

Scene scene2= new Scene(root3,400,400);

GridPane root4 = new GridPane();

root4.setAlignment(Pos.CENTER);

root4.setHgap(10);

root4.setVgap(10);

Scene scene3= new Scene(root4,500,500);

Hyperlink hyperlink = new Hyperlink("Debit");

root3.add(hyperlink, 0, 1);

hyperlink.setOnAction(new EventHandler() {

@Override

public void handle(ActionEvent event) {

getHostServices().showDocument("http://interac.ca/en/interac-online-faq.html");

}

});

Hyperlink hyperlink1 = new Hyperlink("Credit");

root3.add(hyperlink1, 0, 3);

hyperlink1.setOnAction(new EventHandler() {

@Override

public void handle(ActionEvent event) {

getHostServices().showDocument("https://www.paypal.com/ca/signin");

}

});

Hyperlink Cash = new Hyperlink("Cash");

root4.add(Cash, 0, 5);

Image image = new Image("file:src/application/cash.jpg");

ImageView iv = new ImageView();

Cash.setOnAction(new EventHandler() {

@Override

public void handle(ActionEvent event) {

iv.setImage(image);

root4.add(iv, 0, 1);

}

});

Label title3 = new Label("How would you like to pay for your order");

root2.add(title3, 0,6);

title3.setStyle("-fx-font-weight: bold;");

RadioButton radiobutton6 = new RadioButton("Cash");

RadioButton radiobutton7 = new RadioButton("Debit or Credit");

ToggleGroup radioGroup2 = new ToggleGroup();

radiobutton6.setToggleGroup(radioGroup2);

radiobutton7.setToggleGroup(radioGroup2);

VBox vbox3 = new VBox(radiobutton6, radiobutton7 );

root2.add(vbox3, 0, 7, 2, 1 );

Button btn1 = new Button("go back to previous scene");

root2.add(btn1, 0, 12);

Button btn2 = new Button("Submit");

root2.add(btn2, 0, 10);

Button btn3 = new Button("go back to previous scene");

root3.add(btn3, 0, 7);

Button btn4 = new Button("go back to previous scene");

root4.add(btn4, 0, 7);

btn.setOnAction(new EventHandler() {

@Override

public void handle(ActionEvent event) {

primaryStage.setScene(scene1);

if(radioButton1.isSelected()) {

outRadioBtn2.setText("Size of the Pizza : Small");

}

if(radioButton2.isSelected()) {

outRadioBtn2.setText("Size of the Pizza : Medium ");

}

if(radioButton3.isSelected()) {

outRadioBtn2.setText("Size of the Pizza : Large");

}

if(radiobutton4.isSelected()) {

outRadioBtn1.setText("Type of the Pizza : Regular ");

}

if(radiobutton5.isSelected()) {

outRadioBtn1.setText("Type of the Pizza : Feast");

}

nameLabel.setText("Name of the Customer : "+ firstNameFld.getText() +" " + lastNameFld.getText());

String Toppings = null;

if (cb1.isSelected()) {

Toppings = " Chicken ";

cbOut.setText(Toppings);

}

if (cb2.isSelected()) {

Toppings += " Peppers ";

cbOut.setText(Toppings);

}

if (cb3.isSelected()) {

Toppings += " Mushrooms ";

cbOut.setText(Toppings);

}

primaryStage.show();

}

});

btn1.setOnAction(new EventHandler() {

@Override

public void handle(ActionEvent event) {

primaryStage.setScene(scene);

primaryStage.show();

}

});

btn2.setOnAction(new EventHandler() {

@Override

public void handle(ActionEvent event) {

if(radiobutton6.isSelected()) {

primaryStage.setScene(scene3);

}

if(radiobutton7.isSelected()) {

primaryStage.setScene(scene2);

}

primaryStage.show();

}

});

btn3.setOnAction(new EventHandler() {

@Override

public void handle(ActionEvent event) {

primaryStage.setScene(scene1);

primaryStage.show();

}

});

btn4.setOnAction(new EventHandler() {

@Override

public void handle(ActionEvent event) {

primaryStage.setScene(scene1);

primaryStage.show();

}

});

scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());

primaryStage.setScene(scene);

primaryStage.show();

}

public static void main(String[] args) {

launch(args);

}

}

Here is the price list.

image text in transcribed

Pizza 2 ToppingsRegular Feast 3 Toppings 2.5S/Topping Small (108) Small (105) 2.5S/Topping Medium (125) Medium (12S) Large (14S) Large (145) Total Cost of Pizza TypeofPizzaBaseCost NumberofToppings CostPerTopping Pizza 2 ToppingsRegular Feast 3 Toppings 2.5S/Topping Small (108) Small (105) 2.5S/Topping Medium (125) Medium (12S) Large (14S) Large (145) Total Cost of Pizza TypeofPizzaBaseCost NumberofToppings CostPerTopping

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

Students also viewed these Databases questions

Question

I am paid fairly for the work I do.

Answered: 1 week ago

Question

I receive the training I need to do my job well.

Answered: 1 week ago