Question

In Java Write a JavaFX application that allows the user to pick a set of pizza...

In Java

Write a JavaFX application that allows the user to pick a set of pizza toppings using a set of check boxes. Assuming each topping cost 50 cents, and a plain pizza costs $10, display the cost of the pizza.Us an Hbox

thank you!

Homework Answers

Answer #1

Code


import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import javafx.scene.layout.HBox;;


public class PizzaOrder extends Application {
  
@Override
public void start(Stage stage)
{
  
  
CheckBox chkPepperoni = new CheckBox("Pepperoni");
CheckBox chkCheez = new CheckBox("Extra Cheez");
CheckBox chkBacon = new CheckBox("Bacon");
CheckBox chkBlackOlives = new CheckBox("Black olives");
Label price = new Label("Total Cost: ");
//Creating the stop button
Button calculate = new Button("Place Order");

//Instantiating the HBox class
HBox hbox = new HBox();
  
//Setting the space between the nodes of a HBox pane
hbox.setSpacing(10);
  
//Setting the margin to the nodes
hbox.setMargin(chkPepperoni, new Insets(10, 10, 10, 10));
hbox.setMargin(chkCheez, new Insets(10,10,10,10));
hbox.setMargin(chkBacon, new Insets(10,10,10,10));
hbox.setMargin(chkBlackOlives, new Insets(10,10,10,10));
hbox.setMargin(price, new Insets(10, 10, 10, 10));
hbox.setMargin(calculate, new Insets(10, 10, 10, 10));
  
//retrieving the observable list of the HBox
ObservableList list = hbox.getChildren();
  
//Adding all the nodes to the observable list (HBox)
list.addAll(chkPepperoni,chkCheez,chkBacon,chkBlackOlives,calculate,price);   
  
calculate.setOnAction((event) -> {
double pizzaPrice=10.00;
if(chkBacon.isSelected())
{
pizzaPrice+=0.50;
}
if(chkPepperoni.isSelected())
{
pizzaPrice+=0.50;
}
if(chkCheez.isSelected())
{
pizzaPrice+=0.50;
}
if(chkBlackOlives.isSelected())
{
pizzaPrice+=0.50;
}
price.setText("Total Cost: $"+pizzaPrice);
});
  
//Creating a scene object
Scene scene = new Scene(hbox);
  
//Setting title to the Stage
stage.setTitle("Pizza Order");

//Adding scene to the stage
stage.setScene(scene);

//Displaying the contents of the stage
stage.show();
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
  
}
output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java Language: Write an application that asks the user to enter a student ID and a...
Java Language: Write an application that asks the user to enter a student ID and a test letter grade. Create an Exception class names GradeException that contains an Array of valid grade letters that you can use to determine whether a grade entered from the application is valid. In your application, throw a GradeException if the user does not enter a valid letter grade. Catch the GradeException, and then display an appropriate message. In addition, store an 'I' (for incomplete)...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print which of the two values is bigger. If they are the same, print that they are the same. 2. Write a method that accepts three doubles. Calculate and return the average of the three passed double values. 3. Write up a method that accepts a score between 0-10. Print out a message according to the following table. You ay personally decide the boundaries. i.e.,...
Write a java code that allows the user to input any name (up to 10 only)...
Write a java code that allows the user to input any name (up to 10 only) and then sorts and alphabetizes them in an array without using predefined methods (.compareTo(), or any sorter functions) and then print out the results.
Write a Java application with a JavaFX GUI that takes a String input by the user...
Write a Java application with a JavaFX GUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum,...
Write a java program that repeatedly prompts the user to input a string starting with letters...
Write a java program that repeatedly prompts the user to input a string starting with letters from the English alphabet. The program must stop getting input when the user inputs the string “STOOOOP”. Then the program must display the words starting with each letter from the alphabet in a separate line (e.g. you need to make a new line after all words starting with a specific letter are finished.
Write a program in Java that: 1. will prompt user with a menu that contains options...
Write a program in Java that: 1. will prompt user with a menu that contains options to: a. Add a To-Do Item to a todo list. A To-Do Item contains: i. An arbitrary reference number (4; 44,004; etc.) ii. A text description of the item ("Pick up dry cleaning", etc.) iii. A priority level (1, 2, 3, 4, or 5) b. View an item in the list (based on its reference number) c. Delete an item from the list (based...
4) Write a Java program using Conditions: Write a program where it will ask user to...
4) Write a Java program using Conditions: Write a program where it will ask user to enter a number and after that it will give you answer how many digits that number has. Steps: 1) Create Scanner object and prompt user to enter the number and declare variable integer for input 2) Use if else condition with && condition where you will specify the digits of numbers by writing yourself the digit number that should display: Example(num<100 && num>=1), and...
Write a program in C# that allows any number of values between 0 and 10 to...
Write a program in C# that allows any number of values between 0 and 10 to be entered. When the user stops entering the values, display a frequency distribution bar chart. Use asterisks to show the number of times each value was entered. If a given number is not entered, no asterisks should appear on that line. Your application should display error messages if a value outside the acceptable range is entered or if a non-numeric character is entered.
Write a Java application a String input by the user and shows whether the string contains...
Write a Java application a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. needs, at minimum, asl user to input for the String, then...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the computer through a user interface. The user will choose to throw Rock, Paper or Scissors and the computer will randomly select between the two. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should then reveal the computer's choice and print a statement indicating if the user won, the computer won, or if it was a tie. Allow...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT