Week 1 — Logic Circuit Builder
Terminal Utility · Java
The Idea
Every processor, every digital circuit, every piece of computing hardware ultimately runs on one thing: boolean logic. AND, OR, NOT — combine these gates in the right way and you can build anything from a half adder to a CPU.
In this project you'll build a tool for constructing and evaluating logic circuits in the terminal. The user defines a circuit by connecting gates together, sets the input signal values, and the program evaluates the output — propagating the logic through the entire structure automatically.
What makes this project a beautiful fit for OOP is that a logic circuit is a tree of objects. Each gate takes inputs and produces an output. Those inputs can be other gates or raw signals. When you call evaluate() on the root gate, it recursively evaluates its inputs, which evaluate their inputs, all the way down to the signal leaves. The same method call, the same code path — different behaviour at every node.
You decide what gates you want to support, how the user builds a circuit, and what the output looks like. The only constraint is that you support at least four gate types and that evaluation works recursively without any type checks.
Week 1 — Build Your Gate Hierarchy
This week is about the gates and the signals — the raw building blocks of any circuit. No interactive builder yet, just the objects and the evaluation logic.
This week's topic: classes and subclasses.
There are two distinct kinds of nodes in a circuit: gates (which have inputs and logic) and signals (which are just named boolean values at the leaves). These are different enough that Signal should not extend Gate — they just happen to share the same capability of being evaluatable.
You need:
- An abstract base class
Gatethat holds the list of inputs for a gate and declaresevaluate()as abstract. Each gate type overridesevaluate()with its own boolean logic. - At least four concrete subclasses:
AndGate,OrGate,NotGate, andXorGate. Each must implementevaluate()correctly for its gate type.NotGateshould only accept a single input. - A
Signalclass — a leaf node, not a subclass ofGate. It holds a name and a boolean value, and itsevaluate()simply returns that value. - A
Circuitclass (not a subclass ofGate) that holds a root gate and a map of named signals, and exposesevaluate()andprint()methods.
For this week, build a few hardcoded circuits in code and verify they evaluate correctly. For example: AND(OR(A, B), NOT(C)) — set A=true, B=false, C=false and check the output is true.
What you decide:
- Whether
Gateholds its inputs as a list or as named left/right fields - How
Circuitstores and exposes the named input signals - What happens if
NotGateis given more than one input - Any additional gate types you want to support (NAND, NOR, XNOR)
The interactive CLI for building circuits comes in later weeks — for now, hardcoded wiring is fine.