← Back to Week 3 Hub
Workbook 3a — Exercise

Search Engine Logger

Simulate a mini search engine — every launch, search, and exit gets logged to a file with a timestamp  |  Workbook p.34

The Exercise

Create a Java application called search-engine-logger. The program prompts the user for a search term, over and over, until they type X to exit. Your program doesn't have to actually search anything — what it does is log every action to a file called logs.txt.

There are three kinds of actions to log:

launch — written once, the moment the program starts
search — written every time the user enters a search term
exit — written once, when the user types X

Each log line starts with a timestamp in the format yyyy-MM-dd HH:mm:ss, followed by the action. For a search, the search term is appended after the word search. Example entries:

2026-04-22 12:42:20 launch
2026-04-22 12:42:45 search : How to use ChatGPT
2026-04-22 12:43:51 exit

Example Run
Run — Launch, two searches, then exit
Enter a search term (X to exit): how to use ChatGPT
Enter a search term (X to exit): how to forge a camp knife
Enter a search term (X to exit): X

Goodbye!

--- logs.txt ---
2026-04-22 12:42:20 launch
2026-04-22 12:42:45 search : how to use ChatGPT
2026-04-22 12:43:10 search : how to forge a camp knife
2026-04-22 12:43:51 exit
Concepts You'll Use
Flow
1. Open logs.txt (append mode)
2. Write "<time> launch"
3. Prompt for search term
4. If X → write "exit", close, break
5. Else write "search : <term>"
6. Loop back
7. Timestamps via DateTimeFormatter

Workbook 3a, p.34 — Exercise: Search Engine Logger

← Format Dates Search Inventory (ArrayList) →