Lab: Quick-Service P.O.S. (Point of Sale) System

AP Computer Science A

Introduction

In the modern world, retail transactions are handled by a P.O.S. (Point of Sale) system. These systems are responsible for tracking inventory, calculating totals, and managing customer data.

Your task is to design and implement a robust, Object-Oriented P.O.S. program for a restaurant. You will practice managing multiple classes, using ArrayList to store data, and implementing loop-driven user interfaces.


Technical Requirements

To receive full credit, your program must demonstrate the following OOP principles:

  1. Encapsulation: All instance variables must be private. Use constructors and getter methods to access data.
  2. Constants: Use public static final for the tax rate (0.05 or 5%) and avoid "magic numbers" in your calculations. In programming, a magic number is a direct numerical value used in code without explanation or context. It "magically" appears in a formula, making the code harder to read, maintain, and debug.
  3. Input Validation: The system must handle invalid menu selections (e.g., entering 9 when only 1-5 exist) without crashing.
  4. Formatting: Use System.out.printf or DecimalFormat to ensure all currency is displayed with exactly two decimal places.

Program Design (Starter Code)

1. The Item Class

Represents a single menu item.

class Item {
    private String name;
    private double price;

    public Item(String name, double price) {
        this.name = name;
        this.price = price;
    }

    public String getName() { return name; }
    public double getPrice() { return price; }
}

2. The Order Class

Responsible for storing what the customer is buying.

import java.util.ArrayList;

class Order {
    private ArrayList<Item> contents;
    private int orderID;

    public Order(int id) {
        this.orderID = id;
        this.contents = new ArrayList<Item>();
    }

    public void addItem(Item i) {
        contents.add(i);
    }

    public ArrayList<Item> getContents() {
        return contents;
    }

    public double getSubtotal() {
        // TODO: Iterate through contents and sum the prices
        return 0.0;
    }
}

3. The Display & POS Classes

The Display class handles all UI (printing and scanning). The POS class contains your main method and logic for tax and change.

class Display {
    // Note: All UI methods here should be static
    public static int showMenu() {
        // Display options 1-5 and return the user's validated choice
    }

    public static void printReceipt(Order o) {
        // Print the order ID and the list of items
    }
}

class POS {
    public static final double TAX_RATE = 0.05;
    private static int nextOrderNum = 4312;

    public static void main(String[] args) {
        // 1. Create your menu Items (Burger, Fry, Shake)
        // 2. Start a loop for the "New Order"
        // 3. Inside, call Display.showMenu() and use a switch or if-else 
        //    to add items to a new Order object.
    }
}

Expected Behavior

The flow of your program should match the logic below:

Action Logic Requirement
Selecting 1-3 Add the corresponding Item object to the current Order.
Selecting 4 (Total) Calculate: Total = Subtotal + (Subtotal * TAX_RATE). Display all three values: Subtotal, Tax and Total.
Selecting 5 (Cash Out) Prompt for "Amount Tendered." Calculate change. Increment nextOrderNum and start a fresh order.
Invalid Input Print "ERROR: Invalid input" and re-display the menu.

Extending

Bulk Discount: If a customer orders more than 3 of the same item (e.g., 4 orders of Fries), apply a 10% discount to that specific item's price before calculating the final total.