Java Object Design
Project workbook · Path 80

Model a small lending item with explicit state transitions and test checkout and return behavior.

The case

A fictional club lends one tool with ID T1. It starts available, can be checked out once, rejects a second checkout, can be returned once and rejects a second return. This single-object exercise has no users, database or concurrent requests.

ActionExpected stateExpected result
Startavailableinitial
Checkouton loanaccepted
Checkout againon loanrejected
Returnavailableaccepted
Return againavailablerejected
STAGE 1

Identify state and behavior

An object groups a coherent state with operations that preserve its rules. Keep the item identifier stable and make availability private. A class should not expose arbitrary writes that bypass checkout and return. This case is intentionally small enough to describe every valid transition in a table.

Your task

Sketch the class and list its allowed transitions.

Required output

Class contract

Record your result and evidence here or in a separate file.

Review gate

Only two states and two meaningful operations are needed.

If the gate is not met

Remove fields that do not belong to the stated case.

STAGE 2

Implement guarded methods

A method should check its precondition before changing state. Choose a clear result for a rejected operation, such as a boolean, and document it. Do not partially mutate the object before discovering failure. Keep console printing outside the core class so behavior can be tested independently.

Your task

Implement checkout and returnItem methods.

Required output

Encapsulated class

Record your result and evidence here or in a separate file.

Review gate

A duplicate checkout returns false and keeps the item on loan.

If the gate is not met

Check the state before assigning the new state.

STAGE 3

Exercise the transition sequence

Tests should cover successful and rejected transitions and inspect state after each. A test that only checks printed text can miss a corrupted object. Use assertions or explicit checks that fail the process. Keep the test fixture isolated so each scenario starts from a known state.

Your task

Run the five-row sequence in a local JDK and compare each result.

Required output

Transition checks

Record your result and evidence here or in a separate file.

Review gate

Rejected actions preserve the previous state.

If the gate is not met

Reset fixtures between independent cases.

STAGE 4

Explain identity and collections

A collection can hold multiple lending items, but searching by ID introduces another rule: IDs should be unique within that collection. Do not add a database or concurrency layer merely to demonstrate collections. A simple registry extension can show how object identity and lookup differ from a display name.

Your task

Design a two-item extension and a duplicate-ID policy.

Required output

Extension design

Record your result and evidence here or in a separate file.

Review gate

The policy distinguishes an item ID from a human-readable label.

If the gate is not met

Define duplicate behavior before adding an item.

STAGE 5

Document the boundary

A useful README explains the state machine, run commands and limitations. This source does not persist after process exit and cannot safely coordinate simultaneous checkouts from multiple processes. The preparation environment lacks javac, so compilation and runtime checks remain learner tasks rather than claimed verification.

Your task

Package the class, a check runner and expected sequence.

Required output

Java source handoff

Record your result and evidence here or in a separate file.

Review gate

Execution status is explicit and persistence is not claimed.

If the gate is not met

Separate expected behavior from an actual local run log.

Final project

Deliver the class contract, source, transition checker and README. Add a second item and demonstrate that operating on one does not alter the other, using a local JDK when available.

Critical condition

State is private and rejected operations leave it unchanged; supplied source is not represented as a compiled result.

CriterionPointsEvidence
Evidence and correctness30Calculations, source use and results match the supplied case; limitations are honest.
Required artifacts30All five stage outputs and the capstone handoff are present and inspectable.
Reasoning and decisions20Choices, assumptions, alternatives and the case-specific critical condition are explained.
Reproducibility10A reviewer can follow the stated steps and distinguish expected from observed results.
Clear communication10Labels, units, structure and evidence references make the work easy to review.

Score at least 80/100, supply every required artifact, and satisfy the path-specific critical condition. Rework missing evidence before marking complete.

Worked reference

The state sequence is available → on loan → on loan → available → available. The operation results are true, false, true, false. A rejected action leaves state unchanged. The bundled Java source has not been compiled in the preparation environment.

Boundaries

This is in-memory object design, not a persistent or concurrent lending service.