Question

This project is designed to help you practice Graphical User Interfaces (GUI) using Java. Design and...

This project is designed to help you practice Graphical User Interfaces (GUI) using Java. Design and write a class needed to simulate a pizza shop ordering system GUI. Your ordering system should allow the user to select whether the order is to be delivered or picked up, the items ordered from the menu and the name of the person making the order. When the user presses the place order button, the display should show the delivery status, the items ordered, and the price (cheese pizza $10, pepperoni pizza $11, supreme pizza $13, and vegetarian pizza $12)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class PizzaOrderingApp {
  
private static JFrame mainFrame;
private static JPanel mainPanel, namePanel, statusPanel, ordersPanel, submitPanel, resultPanel;
private static JLabel nameLabel, ordersLabel;
private static JTextField nameField;
private static ButtonGroup grp;
private static JRadioButton delivered, picked;
private static JCheckBox cheesePizza, pepperoniPizza, supremePizza, vegeterianPizza;
private static JButton submitButton;
private static JTextArea resultArea;
  
public static void main(String[] args)
{
init();
  
// action listener for submit button
submitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String name = "", status = "";
ArrayList<String> orders = new ArrayList<>();
int total = 0;
  
if(nameField.getText().equals(""))
{
JOptionPane.showMessageDialog(null, "Please enter your name!");
return;
}
name = nameField.getText().trim();
  
if(!delivered.isSelected() && !picked.isSelected())
{
JOptionPane.showMessageDialog(null, "Please select either of the options: delivered OR picked!");
return;
}
if(delivered.isSelected())
status = "delivered";
else
status = "picked up";
  
if(!cheesePizza.isSelected() && !pepperoniPizza.isSelected() && !supremePizza.isSelected()
&& !vegeterianPizza.isSelected())
{
JOptionPane.showMessageDialog(null, "Please check either of the pizzas!");
return;
}
if (cheesePizza.isSelected()) {
orders.add("Cheese Pizza - $10");
total += 10;
}

if (pepperoniPizza.isSelected()) {
orders.add("Pepperoni Pizza - $11");
total += 11;
}

if (supremePizza.isSelected()) {
orders.add("Supreme Pizza - $13");
total += 13;
}

if (vegeterianPizza.isSelected()) {
orders.add("Vegeterian Pizza - $12");
total += 12;
}

String result = "Name: " + name + "\n"
+ "Order Status: " + status + "\n"
+ "Orders:\n";
int i = 0;
for (String order : orders) {
result += ++i + ". " + order + "\n";
}
result += "------------------------------------\n"
+ "Total: $" + total;

resultArea.setText(result);
}
});
}
  
private static void init()
{
mainFrame = new JFrame("Pizza Shop");
mainPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
  
namePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
nameLabel = new JLabel("Your name: ");
nameField = new JTextField(20);
namePanel.add(nameLabel);
namePanel.add(nameField);
  
statusPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
grp = new ButtonGroup();
delivered = new JRadioButton("Delivered");
picked = new JRadioButton("Picked Up");
grp.add(delivered);
grp.add(picked);
statusPanel.add(delivered);
statusPanel.add(picked);
  
ordersPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
cheesePizza = new JCheckBox("Cheese Pizza - $10");
pepperoniPizza = new JCheckBox("Pepperoni Pizza - $11");
supremePizza = new JCheckBox("Supreme Pizza - $13");
vegeterianPizza = new JCheckBox("Vegeterian Pizza - $12");
ordersPanel.add(cheesePizza);
ordersPanel.add(pepperoniPizza);
ordersPanel.add(supremePizza);
ordersPanel.add(vegeterianPizza);
  
resultPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
ordersLabel = new JLabel("Your orders:\n");
resultArea = new JTextArea(7, 25);
resultPanel.add(ordersLabel);
resultPanel.add(resultArea);
  
submitPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
submitButton = new JButton("Submit");
submitPanel.add(submitButton);
  
mainPanel.add(namePanel);
mainPanel.add(statusPanel);
mainPanel.add(ordersPanel);
mainPanel.add(resultPanel);
mainPanel.add(submitPanel);
  
mainFrame.add(mainPanel);
mainFrame.setSize(650, 300);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setLocationRelativeTo(null);
mainFrame.setResizable(false);
mainFrame.setVisible(true);
}
}

****************************************************************** SCREENSHOT *********************************************************

Add a comment
Know the answer?
Add Answer to:
This project is designed to help you practice Graphical User Interfaces (GUI) using Java. Design and...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help on following Java GUI problem: Write a program that lets a user display and...

    Need help on following Java GUI problem: Write a program that lets a user display and modify pictures. Create a window. Add four buttons so that clicking a particular button will shift the image by a small amount in the north, south, east or west direction inside the window. Add a menu bar with two menus: File and Image. The File menu should contain an Open menu item that the user can select to display JPEG and PNG files from...

  • Using Dr Java Objective: Create a game of video poker with a graphical user interface (GUI)....

    Using Dr Java Objective: Create a game of video poker with a graphical user interface (GUI). The player should start with $100, and then the system deals out 5 playing cards. After the player sees the cards they are then asked to wager $10, $20, $50, or $100. Next the user picks which cards they wish to throw away, and then the system deals more cards in their place. Once this has concluded money are awarded by these criteria: Nothing...

  • In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student...

    In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student information system. The application should allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow student to edit ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique...

  • Project overview: Create a java graphics program that displays an order menu and bill from a...

    Project overview: Create a java graphics program that displays an order menu and bill from a Sandwich shop, or any other establishment you prefer. In this program the design is left up to the programmer however good object oriented design is required. Below are two images that should be used to assist in development of your program. Items are selected on the Order Calculator and the Message window that displays the Subtotal, Tax and Total is displayed when the Calculate...

  • Help Please on JAVA Project: Validating the input is where I need help. Thank you Requirements...

    Help Please on JAVA Project: Validating the input is where I need help. Thank you Requirements description: Assume you work part-time at a sandwich store. As the only employee who knows java programming, you help to write a sandwich ordering application for the store. The following is a brief requirement description with some sample output. 1. Selecting bread When the program starts, it first shows a list/menu of sandwich breads and their prices, then asks a user to select a...

  • Help with java . For this project, you will design and implement a program that analyzes...

    Help with java . For this project, you will design and implement a program that analyzes baby name popularities in data provided by the Social Security Administration. Every 10 years, the data gives the 1,000 most popular boy and girl names for kids born in the United States. The data can be boiled down to a single text file as shown below. On each line we have the name, followed by the rank of that name in 1900, 1910, 1920,...

  • Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use...

    Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Use arrays or ArrayList for storing objects. Proper design techniques. Project Requirements Your job is to implement a simple amusement park information system that keeps track of admission tickets and merchandise in the gift shop. The information system consists of three classes including a class to model tickets, a...

  • please help!!!! JAVA I done the project expect one part but I still give you all...

    please help!!!! JAVA I done the project expect one part but I still give you all the detail that you needed... and I will post my code please help me fix the CreateGrid() part in main and make GUI works    List Type Data Structures Overview : You will be implementing my version of a linked list. This is a linked list which has possible sublists descending from each node. These sublists are used to group together all nodes which...

  • Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an...

    Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an order at a fast-food burger joint. This class will be used in Part B, when we work with a list of orders. As vou work through this part and Part B, draw a UML diagram of each class in using the UML drawing tool 1) Create a new Lab5TestProject project in Netbeans, right-click on the lab5testproject package and select New>Java Class 2) Call your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT