Part 3: how I used AI
Tools
Claude Code, Anthropic’s coding agent, in my terminal, for both parts. It ran the research, drafted the Java and the tests, drew the diagram and ran the builds. I set the rules, made the decisions, and decided what was good enough to send.
I worked the way I would lead a fast team: say what matters, ask the awkward question, refuse the first answer when it is wrong, and insist on proof.
How I worked
I followed the loop that most current guidance on coding agents converges on: understand first, plan, build in small steps, and make the agent prove each claim. Here is what each step looked like on this exercise.
1. Understand the domain before any code
My first prompt was not “write the pricer”. It was a request for research on how open-loop transit payments work: what a reader on a bus does when it is offline, how a bank card is authorised when the price is not known yet, what the passenger sees in their banking app and when, and how systems differ between the Netherlands, Türkiye, the UK, the US, Australia and Japan.
The agent ran several research passes in parallel and produced a long cited report. I then tested it with pointed questions:
- Can a bank accept a payment before the price is known?
- Why do “transit rules” apply when the card is an ordinary debit card? (They are rules for the merchant category, not for the card.)
- Does Littlepay talk to the card schemes itself, or through an acquirer?
Those answers are why the design note separates “the reader lets you on” from “the back office prices the trip”, and why decision 6 (authorise per trip, capture once a day) is marked as something to confirm with the acquirer rather than stated as fact.
2. Plan, with my constraints written down
Before any code I had the agent write a plan and I gave it the rules for the work. The ones that mattered most:
- Do exactly what the brief asks. Real-world extras (capping, deny lists, debt recovery) go in the design note or “what next”, not in Part 1.
- Design for change: new operators, new fares, fares that change over time, and old trips that must keep their old price.
- Every assumption in the README needs a test that proves it.
- Published test card numbers only.
- Nothing is done until the tests have been run and I have seen the output.
3. Build in small steps, tests alongside
The core went up in layers: the fare table, then pairing taps into trips, then the anomalies, then versioned fares per operator (FareCatalogue, Tariff, IncompleteTripPolicy). The suite grew from 65 tests to 80 as the rules were added. The agent ran ./gradlew test after each change and showed me the result, so I was reviewing evidence, not a claim that it worked.
4. A second, independent review
An agent that wrote the code is a poor judge of it. So I had a separate review pass, with a fresh context, check the code against what the README claimed. That is where the two real bugs below were found. I ran the same kind of review on the design note and on the demo site.
What I changed or rejected
Three bugs the reviews found, each a case where the code contradicted my own README.
- Conflicting tap IDs. When two taps shared an ID but differed in content, the code kept the first one it received. That made the price depend on arrival order, which is the one property I was claiming it did not have. Now no copy of a conflicting ID is trusted, both are reported, and the shuffle test includes a conflicting pair.
- Unknown stops. A tap off at a stop missing from the fare table was silently dropped. The tap on then looked incomplete and the passenger was charged the maximum fare for a trip they had finished. Now the whole trip is reported and nothing is charged, with tests in both directions.
- No fare between two known stops. In a final read-through before sending, I found that a trip between two stops the fare table knows, but has no fare for, threw an exception and stopped the whole run. One odd trip should never block everyone else’s. It is now reported as
NO_FARE_BETWEEN_STOPS, with a test.
Claims I made the agent take back.
- The demo site’s footer said every number on the page came from the Java engine. Not true: the ledger in the “Charge” section is a simulation of my Part 2 design. The wording now says so.
- The design note described the ledger version as increasing on every tap. A replayed tap would then have produced a second charge. It now increases only when the card’s priced state changes.
- The architecture walkthrough had invented labels for compute I never specified. I removed them. The diagram only names services the design note names.
- The research wanted token-only handling everywhere. The brief asks for the PAN in the Part 1 output, so I followed the brief.
Pan.toString()masks the number so it cannot leak into logs, and tokenisation lives in the Part 2 design.
Choosing the right tools and keeping the code clean
An agent will happily add a framework, a library and three layers of abstraction to a problem that needs none of them. The test I applied to every choice was the same: can I say in one sentence what it is for? If not, it stays out.
Tools
- Java 21, Gradle and JUnit 5, and nothing else. The build fails on any compiler warning. JUnit is the only dependency, and only for tests. The brief asks for logic and tests, not an application, so there is no Spring, no CSV library and no file handling. Everything in the repository is something a reviewer needs to read.
- The Gradle wrapper is committed, so the only thing you install is Java. I checked that on a clean copy with an empty cache.
- AWS services picked for a requirement, not for the diagram. Each service in the design note answers one of the brief’s considerations: a stream partitioned by card so one card’s taps stay in order, an append-only table so a resent tap is harmless, one-off timers to close open trips, a separate vault so card numbers stay out of the pricing path. Where I was not sure a choice would hold in production, the note says so.
- Compile, don’t rewrite. For the demo I compiled the Java to JavaScript with TeaVM. A second implementation in JavaScript would have been quicker to build and impossible to trust.
- Left out on purpose. Property-based testing would be a good next step, and it is in “what I would do next”. I did not add it just to look thorough.
Code
- A pure function at the centre.
TripPricer.price(taps)reads nothing and writes nothing. The same taps give the same trips in any order, which is what makes it easy to test and safe to re-run. - Small classes with one job each. Thirteen classes; the largest is under 200 lines. The README has a table of what each one is responsible for.
- Values that cannot be wrong. Taps, trips, tariffs and anomalies are immutable records. Money is
BigDecimalwith exact two-place scale, never floating point.Pan.toString()masks the card number so it cannot end up in a log by accident. - Change is data, not edits. A new fare, a new operator or a different incomplete-trip rule is a new
Tariffin the catalogue. The pricer does not change, and a test proves January’s trips price the same after February’s fares are added. - Nothing is silently dropped. A tap that cannot be charged is returned as an anomaly with a reason. Guessing is how passengers get overcharged.
- Names from the domain. Tap, trip, tariff, fare, stop: the words in the brief are the words in the code, and the test names read as the rules they check.
How I satisfied myself it is correct
- The brief’s expected output is asserted character for character, and the other three outcomes of the sample are asserted too.
- Each assumption in the README has a test. If I could not write the test, I did not keep the assumption.
- Order does not matter. One test shuffles the input 25 times with fixed seeds, including resent taps and a conflicting pair, and the result never changes. The Part 2 design rests on this property, so it is the test I care most about.
- A clean-machine build. The tests pass from a fresh copy with an empty Gradle cache: Java 21 and
./gradlew test, nothing else. - The same code, run a second way. For the demo I compiled the Java to JavaScript with TeaVM instead of rewriting it, so the page cannot drift from the submission. It compares the engine’s output for taps 1 and 2 with the brief’s expected line, live, in the browser. The demo was then driven end to end in a real browser, on phone and desktop sizes, before I published it.
Passing tests do not prove the behaviour is right, only that it matches what I asked for. The bugs above passed every test that existed at the time. What caught them was reading the code against the claims.
What I would do differently
- Write the failing test first, every time. I did tests alongside the code. A test written from the README before the implementation would have caught these bugs without a review.
- Smaller commits as I go. I kept the work uncommitted until the end so that the history would be clean. On a team I would commit each layer as it passed, because small steps are easier to review and to undo.
Where AI could help the team
- Rule changes into test cases. Card scheme rulebooks change about twice a year. An agent could diff a new edition and propose test cases for the fare and charge logic, for an engineer to accept or reject.
- Review against the claim, not just the diff. The most useful thing the agent did here was check code against the document that described it. The same check on every pull request (does the code still do what the README, the runbook and the API docs say?) is cheap and catches the bugs that tests written by the same author miss.
- Triage of the exceptions queue. Summarise orphan taps, conflicting IDs and unknown stops by reader and operator, so a faulty device is noticed before passengers complain.
- A first pass on each new market. A cited summary of a new country’s rules and existing systems in an afternoon, then verified by an engineer. The research for this exercise is a small example.