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
Core logic that accepts a list of ingredients and a delivery flag, then returns a fully built pizza object.
Ingredient Hierarchy
Base Ingredient class used by concrete ingredients such as cheese, meats, and vegetables.
Pepperoni Ingredient
Example of a specific ingredient subclass with its own description and cost.
PizzaMaker Test Code
Original JUnit-style tests later adapted into a custom test runner for easier execution without external libraries.
Test Runner 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
- How to design and structure an object-oriented program in Java using composition and inheritance.
- How to represent real-world concepts (toppings, pizza, delivery) as classes and objects.
- How to create a small test harness to validate logic without relying on external frameworks.
- How to organize a Java project so it’s easy to understand on GitHub and run locally.
Explore the Code
You can view the full source, including all ingredient classes and the test runner, in the GitHub repository.