Java Case Study

Pizza Maker — OOP & Testing

A console-based Java project that builds pizzas from ingredient objects, calculates pricing, and uses a custom test runner to verify multiple combinations without external libraries.

Screenshots

PizzaMaker Class

Screenshot of the PizzaMaker Java class in VS Code.

Core logic that accepts a list of ingredients and a delivery flag, then returns a fully built pizza object.

Ingredient Hierarchy

Screenshot of the Ingredient base class in Java.

Base Ingredient class used by concrete ingredients such as cheese, meats, and vegetables.

Pepperoni Ingredient

Screenshot of a Pepperoni ingredient class in Java.

Example of a specific ingredient subclass with its own description and cost.

PizzaMaker Test Code

Screenshot of the PizzaMaker test logic in Java.

Original JUnit-style tests later adapted into a custom test runner for easier execution without external libraries.

Test Runner Output

Screenshot of PizzaMaker test runner console output.

Console output showing the results of multiple pizza combinations being tested for cost and delivery flags.

Project Overview

The goal of this assignment was to practice object-oriented design in Java by modeling a pizza builder. The program uses an Ingredient abstraction along with concrete classes for cheese, meat, and vegetable toppings. The PizzaMaker class coordinates ingredient selection, delivery options, and final price calculation.

Instead of hard-coding every pizza, the program builds pizzas dynamically from a list of ingredients. This makes it easy to adjust or add new ingredients in the future, and it reflects how composition can be used to model real-world items.

Key Logic (Pricing & Composition)

A simplified example of how the pizza is assembled and priced:

public class PizzaMaker {

    public Pizza makePizza(List<Ingredient> ingredients, boolean delivery) {
        double total = 0.0;
        for (Ingredient ingredient : ingredients) {
            total += ingredient.getCost();
        }

        if (delivery) {
            total += 3.0; // delivery fee
        }

        Pizza pizza = new Pizza();
        pizza.setIngredients(ingredients);
        pizza.setTotalCost(total);
        pizza.setDeliveryYn(delivery);

        return pizza;
    }
}

The real project uses the concrete ingredient classes, but this snippet highlights the overall approach: iterate ingredients, sum costs, add delivery, and return a composed Pizza object.

What I Learned

Explore the Code

You can view the full source, including all ingredient classes and the test runner, in the GitHub repository.