GNGiseldo Neo and Alana NeoBooks
Introduction to Programming in Java17 / 25

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.

Reference architecture of TutorJavaBot.

Figure 16.1. Reference architecture of TutorJavaBot.

16.2 Required Features

The program must:

  1. run on Java 21 or later;
  2. stay active until the exit command is entered;
  3. recognize hi, help, tip, quiz, history, and exit;
  4. normalize whitespace and letter casing;
  5. reject empty input without recording it;
  6. store interactions in memory;
  7. save the history in UTF-8 when exiting;
  8. handle I/O failures without crashing abruptly;
  9. prevent duplicate commands;
  10. pass both the automated tests and the manual script from the previous chapter.
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

CommandResponse or effect
hibot introduction
helpcommand list retrieved from the registry itself
tipa Java tip
quizquestion and answer validation
historyrecent interactions, without recording the query itself
exitends the session and attempts to save the history
unknowndirects 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

  1. Start the program and type HELP.
  2. Run hi, tip, and an unknown command.
  3. Press Enter with no text.
  4. Check history.
  5. Run quiz with both a correct and an incorrect answer.
  6. Type EXIT.
  7. 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

CriterionWeight
command behavior and contract30%
organization and encapsulation20%
error handling and persistence15%
automated tests15%
readability and naming10%
console experience10%

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 Command implementation.

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.