In: Computer Science
Design and implement a Java program that creates a GUI that will allow a customer to order pizza and other items from a Pizza Paarlor. The customer should be able to order a variety of items which are listed below. The GUI should allow the customer (viaJavaFX UI Controls - text areas, buttons, checkbox, radio button, etc.) to input the following information:
Name of the customer First Name Last Name
Phone number of the customer
Type of food being order options are:
pizza calzone garlic knots baked ziti antipasto
Quantity of each food item being ordered
Additional information
Pizza size Small round Large round Sicilian Pizza toppings Pepperoni Sausage Meatballs Mushrooms Onions Peppers Extra cheese
Address for delivery Street Number Street Name Conditions: Small pies can have no more than 4 toppings. Large pies can have as many toppings as the customer would like. Sicilian pies can have no toppings.
The customer must specify the quantity of each item they have chosen.
The number of each item ordered cannot exceed 50.
The GUI will have two buttons. The first will be used to create a running total of the current order.
This button should be clicked every time an item is added to the order to give a running total of the current order.
The second button will be used to display the following:
Name of customer Phone Number of customer All items and quantity ordered
The grand total for the order Pricing Base Price for items : Small Plain Pie – $11.25 Large Plain Pie – $14.00 Sicilian Pie – $18.50 Calzone - $7.75 Garlic Knots -$3.50 Baked Ziti - $11.00 AntiPasto - $12.50 Additional fees for Toppings: Small Pie - $2.00 per topping Large Pie - $3.00 per topping Once calculated the system should display the Name and Phone Number of the customer, Address for delivery, items ordered and quantity for each and the cost of the entire purchase. Error checking of all data is required.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.ListSelectionModel;
public class PizzaLand extends JFrame
{
private JLabel name = new JLabel("Customer Name:");
private JLabel email = new JLabel("Email Address:");
private JLabel telNo = new JLabel("Telephone No:");
private JLabel pizza = new JLabel("Pizza Type:");
private JLabel crust = new JLabel("Crust Type:");
private JLabel size = new JLabel("Size:");
private JLabel info = new JLabel("Pizza info:");
private JTextField tName = new JTextField();
private JTextField tEmail = new JTextField();
private JTextField tTelNo = new JTextField();
private String[] pizzaType = {"Cheese & Tomatoes", "Vegetarian", "Anchovies", "Superb meat lover", "Juicy chicken", "All cheezey", "Seafood heaven", "Sambal berapi"};
private JList lPizza = new JList(pizzaType);
private JScrollPane scrollPizza = new JScrollPane(lPizza);
private String[] crustType = {"Super thin", "Thin & crispy", "Hand tossed", "Deep pan", "Cheesy edge"};
//private String comboSize;
// private double pizzaPrice;
private String[] comboSize = {"Personal 6 inch", "Regular 9 inch", "Large 12 inch", "Extra large 15 inch"};
//private double[] pizzaPrice = {10.00, 20.00, 25.00, 30.00};
private JComboBox cCrust = new JComboBox(crustType);
private JComboBox cSize = new JComboBox(comboSize);
private JRadioButton delivery = new JRadioButton("Delivery", true);
private JRadioButton pickUp = new JRadioButton("Pick up", true);
private JButton submit = new JButton("Submit");
private JButton clear = new JButton("Clear");
private JTextArea aInfo = new JTextArea(1, 2);
private JPanel p1 = new JPanel();
private JPanel p2 = new JPanel();
private double amount;
//int[] pizzaItem;
String selected = "";
public PizzaLand()
{
lPizza.setVisibleRowCount(4);
lPizza.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
Container pane = getContentPane();
pane.setLayout(new GridLayout(2, 1, 5, 5));
p1.setLayout(new GridLayout(4, 4));
p1.add(name);
p1.add(tName);
p1.add(email);
p1.add(tEmail);
p1.add(telNo);
p1.add(tTelNo);
p1.add(pizza);
p1.add(scrollPizza);
p1.add(crust);
p1.add(cCrust);
p1.add(size);
p1.add(cSize);
p1.add(delivery);
p1.add(pickUp);
p1.add(submit);
p1.add(clear);
p2.setLayout(new BorderLayout());
p2.add(info, "West");
p2.add(aInfo, "Center");
pane.add(p1);
pane.add(p2);
action listener = new action();
delivery.addActionListener(listener);
pickUp.addActionListener(listener);
submit.addActionListener(listener);
clear.addActionListener(listener);
item listener1 = new item();
lPizza.addListSelectionListener(listener1);
}
class action implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object choice = e.getSource();
//Object radioB = e.getSource();
if (choice == submit)
{
String item1 = tName.getText();
String item2 = tEmail.getText();
String item3 = tTelNo.getText();
int item4 = cCrust.getSelectedIndex();
int item5 = cSize.getSelectedIndex();
if (choice == delivery)
{
if (cSize.getSelectedItem().equals("Personal 6 inch"))
{
amount = 10+5;
}
else if (cSize.getSelectedItem().equals("Regular 9 inch"))
{
amount = 20+5;
}
else if (cSize.getSelectedItem().equals("Large 12 inch"))
{
amount = 25+5;
}
else if (cSize.getSelectedItem().equals("Extra large 15 inch"))
{
amount = 30+5;
}
}
else if (choice == pickUp)
{
if (cSize.getSelectedItem().equals("Personal 6 inch"))
{
amount = 10;
}
else if (cSize.getSelectedItem().equals("Regular 9 inch"))
{
amount = 20;
}
else if (cSize.getSelectedItem().equals("Large 12 inch"))
{
amount = 25;
}
else if (cSize.getSelectedItem().equals("Extra large 15 inch"))
{
amount = 30;
}
}
aInfo.setText(item1 + "\n" + item2 + "\n" + item3 + "\n" + selected + "\n" + crustType[item4] + "\n" + comboSize[item5] + "\nTotal price: RM" + String.format("%.2f", amount));
}
else if (choice == clear)
{
aInfo.setText("");
}
}
}
class item implements ListSelectionListener
{
public void valueChanged(ListSelectionEvent e)
{
String str = "";
int selectedIndex[] = lPizza.getSelectedIndices();
for (int i=0; i<selectedIndex.length; i++)
{
int index = selectedIndex[i];
str += pizzaType[index];
}
selected = str;
}
}
public static void main (String []args)
{
PizzaLand frame = new PizzaLand();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Order your pizza from PizzaLand. Satisfaction guaranteed!");
frame.setSize(650, 650);
frame.setVisible(true);
}
}