Final Project: TutorJavaBot
An integrated, testable, and extensible deliverable
16.1 Objective
Build a console chatbot that applies the fundamentals and design decisions studied so far. The deliverable should work reliably, report errors clearly, and allow adding new commands without changing the core processor.

Figure 16.1. Reference architecture of TutorJavaBot.
16.2 Required Features
The program must:
- run on Java 21 or later;
- stay active until the
exitcommand is entered; - recognize
hi,help,tip,quiz,history, andexit; - normalize whitespace and letter casing;
- reject empty input without recording it;
- store interactions in memory;
- save the history in UTF-8 when exiting;
- handle I/O failures without crashing abruptly;
- prevent duplicate commands;
- pass both the automated tests and the manual script from the previous chapter.
16.3 Recommended Architecture
ConsoleApplication
└── TutorJavaBot
├── CommandRegistry
│ └── Map<String, Command>
└── History
└── List<String>
Responsibilities:
ConsoleApplication: input, output, and application lifecycle;TutorJavaBot: coordinates command processing and history;CommandRegistry: registers and looks up commands;Command: polymorphic contract;History: records, queries, and saves interactions.
Do not create classes just to increase the file count. Every split should reduce a real responsibility.
16.4 Command Contract
| Command | Response or effect |
|---|---|
hi | bot introduction |
help | command list retrieved from the registry itself |
tip | a Java tip |
quiz | question and answer validation |
history | recent interactions, without recording the query itself |
exit | ends the session and attempts to save the history |
| unknown | directs the user to type help |
Define an “interaction” as a pair consisting of a processed input and its response. Use this exact definition consistently across the counter, the history, and the tests.
16.5 Implementation Roadmap
16.5.1 Stage 1 — Minimal Domain
Implement History and its tests:
- reject empty input;
- record two lines per interaction;
- return a read-only copy;
- compute the total correctly.
16.5.2 Stage 2 — Commands
Implement the interface:
interface Command {
String name();
String execute();
}
Create one class per command whenever it has its own rule. Register the implementations in Map<String, Command>.
16.5.3 Stage 3 — Coordination
TutorJavaBot normalizes input, queries the registry, and records the result. Console and file operations should not appear inside simple command implementations.
16.5.4 Stage 4 — Persistence
Use Files.write or Files.writeString and propagate IOException to the application boundary. The console layer decides what message to display.
16.5.5 Stage 5 — Validation
Run:
./scripts/validate-examples.ps1
quarto render --to html
Then walk through the manual acceptance cases below.
16.6 Acceptance Script
- Start the program and type
HELP. - Run
hi,tip, and an unknown command. - Press Enter with no text.
- Check
history. - Run
quizwith both a correct and an incorrect answer. - Type
EXIT. - Open the generated file and compare it with the displayed interactions.
Empty input, history queries, and the exit command must not increment the total interaction count.
16.7 Evaluation Criteria
| Criterion | Weight |
|---|---|
| command behavior and contract | 30% |
| organization and encapsulation | 20% |
| error handling and persistence | 15% |
| automated tests | 15% |
| readability and naming | 10% |
| console experience | 10% |
16.8 Reference Implementation
A complete implementation with no external libraries is in examples/src/Chapter16Project.java. Read it only after finishing your own first version, and compare design decisions rather than just lines of code.
16.9 Optional Extensions
- load quiz questions from a file;
- persist a timestamp for each interaction;
- migrate tests to JUnit;
- build a graphical interface with JavaFX;
- expose the processor through an API;
- integrate a language model behind a new
Commandimplementation.
Every extension should begin with a contract and a test. External resources must never compromise the core functionality of the chatbot.
Definition of done
The deliverable is ready when it compiles cleanly from scratch, passes its tests, completes the acceptance script, and can accept a new command without editing the central processor.