Question

In: Computer Science

Design and implement a Java program that creates a GUI that will allow a customer to...

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.

Solutions

Expert Solution

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);
}
}

Related Solutions

Give an example of a program in java that creates a GUI with at least one...
Give an example of a program in java that creates a GUI with at least one button and several textfields. Some of the textfields should be for input and others for output. Make the output textfields uneditable. When the button is clicked, the input fields should be read, some calculation performed and the result displayed in the output textfield(s).
Java - Design and implement an application that creates a histogram that allows you to visually...
Java - Design and implement an application that creates a histogram that allows you to visually inspect the frequency distribution of a set of values. The program should read in an arbitrary number of integers that are in the range 1 to 100 inclusive; then produce a chart similar to the one below that indicates how many input values fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for each value entered. Sample...
I need to design and implement a JAVASCRIPT program that will allow us to determine the...
I need to design and implement a JAVASCRIPT program that will allow us to determine the length of time needed to pay off a credit card balance, as well as the total interest paid. The program must implement the following functions: displayWelcome This function should display the welcome message to the user explaining what the program does. calculateMinimumPayment This function calculates the minimum payment. It should take balance and minimum payment rate as arguments and return the minimum payment. So...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project Details: Your program should use 2D arrays to implement simple matrix operations. Your program should do the following: • Read the number of rows and columns of a matrix M1 from the user. Use an input validation loop to make sure the values are greater than 0. • Read the elements of M1 in row major order • Print M1 to the console; make...
Design and implement a Python program which will allow two players to play the game of...
Design and implement a Python program which will allow two players to play the game of Tic-Tac-Toe in a 4x4 grid! X | O | X | O -------------- O | O | X | O -------------- X | X | O | X -------------- X | X | O | X The rules for this game is the same as the classic, 3x3, game – Each cell can hold one of the following three strings: "X", "O", or "...
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads...
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads in the principle 2) reads in additional money deposited each year (treat this as a constant) 3) reads in years to grow, and 4) reads in interest rate And then finally prints out how much money they would have each year. See below for formatting. Enter the principle: XX Enter the annual addition: XX Enter the number of years to grow: XX Enter the...
Exercise Overview Implement a Java program that creates math flashcards for elementary grade students. User will...
Exercise Overview Implement a Java program that creates math flashcards for elementary grade students. User will enter his/her name, the type (+, -, *, /), the range of the factors to be used in the problems, and the number of problems to work. The system will provide problems, evaluate user responses to the problems, score the problems, and provide statistics about the session at the end. Functional Requirements User enters name at the beginning of a session. System covers four...
Design and implement a C++ program with functions to calculate the pre-tax charge: If the customer...
Design and implement a C++ program with functions to calculate the pre-tax charge: If the customer subscribes to a phone plan called Plan200, then he is charged $5 for the first 200 minutes. For each additional minutes, the customer will be charged $0.10. If the customer subscribes to a phone plan called Max20, then he is charged $0.05 for each minute up to $20. (I.e., the customer never needs to pay more than $20.) If the customer is not subscribed...
Language: Java Design and implement a program that implements an Interpolation Search method. Interpolation search is...
Language: Java Design and implement a program that implements an Interpolation Search method. Interpolation search is similar to binary search, except it tries to begin the search nearer to the location of the item. Instead of the using the middle value of the sorted array, interpolation search estimates the location of the target with respect to the first & last values in the array. The implementation is the same as binary search except that you should calculate the mid value...
in a gui ' in java write a program that draws equal a simple fence with...
in a gui ' in java write a program that draws equal a simple fence with vertical, spaced slats backed by two boards. Behind the fence show a simple house support Make sure the in the und. house is visible between the slats in the fence.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT