Project - MG Pizza

Jed Saxon

10/2022

Table of Contents

The Project

Source Code

A project completed in the Certificate IV of IT. It is a simple GUI that implements a pizza ordering system with business requirements implemented and tested using JUnit.

The frontend was done using the Swing framework. When the user first enters the program, they are asked for their login details. The login window doesn't work and will authenticate everyone using the same user, but the ability to incorporate an API is most certainly there. The user interface can be found in the gallery section bellow.

There are 3 types of pizzas that have different costs. In addition, the size of the pizza selected will affect the cost too. Thankfully, the object-oriented code solves this issue by encapsulating a getCost() function. Bellow is the code used to make it work.

Pizza.java - source

public double getCost() {
    // small, medium and large sizes are 1, 2 and 3 respectively
    // The costs based on the sizes are 6, 10, and 14 respectively

    int size = 0;
    switch (getSize()) {
        case "Small":
            size = 1;
            break;
        case "Medium":
            size = 2;
            break;
        case "Large":
            size = 3;
            break;
    }

    double cost = 4.0 * (double)size + 2.0;

    // since "deluxe" pizzas cost 2 dollars more, we just add two to them.
    String type = getType();
    if (type.equals("Marinara") || type.equals("Meat Lovers") || type.equals("Mexicana"))
    {
        cost += 2;
    }
    return cost;
}

User Interface

The user interface was designed a few simple sketches, with feedback taken in order to meet all requirements.

Login

Image of the login screen Image of the login screen

As stated above, when the user enters the program, this window pops up, asking for a username and password. In the code, the login button will fire the event loginListener with the username and password as inputs. The events, in this case, are handled using EventManagers which contain static methods to add and remove event listeners/subscribers. This same technique I used for all other events to ensure all other frames are decoupled from each other.

LoginInterfaceFrame.java - source

private ActionListener loginListener = new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        // The password is in a weird format, so actually convert it to a string
        String unencryptedPassword = String.valueOf(passwordTextField.getPassword());
        LoginRequestEventManager.fireEvent(usernameTextField.getText(), unencryptedPassword);
    }
};

LoginRequestEventManager.java - source

/**
 * The LoginEventManager handles the firing of the logging in requests, and
 * controls the listeners
 */
public class LoginRequestEventManager {

    private static ArrayList<ILoginListener> listeners = new ArrayList<>();

    public static void addListener(ILoginListener newListener) {
        listeners.add(newListener);
    }

    public static void removeListener(ILoginListener listener) {
        listeners.remove(listener);
    }

    public static void fireEvent(String username, String password) {
        for (ILoginListener listener : listeners) {
            listener.onLoginRequest(username, password);
        }
    }
}

Filling In Pizzas

This part of the program had a few requirements. Firstly, the address should be empty if the customer does not want their pizza to be delivered. Secondly, There must be a way to create new pizzas following the same business logic as above of course. Thirdly, the total cost must update for every new pizza that is added.

Image of the empty pizza ordering interface Image of the empty pizza ordering interface
Image of the pizza ordering interface with a few options selected Image of the pizza ordering interface with a few options selected