Part 7 of 7 · 2 min read
Exercises
Easy
Easy 1: Rename (20 minutes)
Rename ten badly named items (such as chk, data, Manager, flag, doIt) and say what each does.
Done when: ten names with a reason.
Hint
Say the job in one verb.
Easy 2: Shape choice (20 minutes)
Choose class, record, enum or interface for: seat, seat status, payment method, money amount, notification channel.
Done when: five choices with a reason.
Hint
Ask whether it changes, and whether the set is fixed.
Easy 3: Money (20 minutes)
In Java, add 0.1 and 0.2 as doubles and print the result. Then add 10 and 20 as cents.
Done when: two printed results and one sentence on the difference.
Hint
Expect 0.30000000000000004.
Medium
Medium 1: Add blocks (30 minutes)
Move the blocking check into Booking as blocks(Room, TimeSlot) and update BookingService.book.
Done when: compiling code that behaves as before.
Hint
The service loop becomes if (b.blocks(room, slot)).
Medium 2: Pricing (30 minutes)
Add the PricingStrategy interface with two implementations, one free and one with a flat price per hour. Use it in a method quote(Booking).
Done when: two classes, one method and two printed quotes.
Hint
The flat-price class needs a rate, so it has a constructor.
Medium 3: Remove nulls (30 minutes)
Change findBooking(String id) so that it returns Optional<Booking>. Update cancel.
Done when: no null appears in the code.
Hint
Use Optional.empty() and orElseThrow.
Hard
Hard 1: Review a messy answer (45 minutes)
Write a 60-line messy answer to "Design a parking lot" using all the bad habits in section 5. Then fix it, and list each change.
Done when: a before and after with a list of ten changes.
Hint
Count public fields, nulls and long methods.
Hard 2: 15-minute code (45 minutes)
Solve "Design a vending machine" in 15 minutes of coding only. After, mark what you wrote in full and what you left as a signature.
Done when: compiling code and a two-column list.
Hint
Decide before you start what stays a signature.
Hard 3: Style guide (50 minutes)
Write a one-page personal style guide for LLD rounds with ten rules, each with a reason and an example.
Done when: ten rules on one page.
Hint
Each rule should fit in one sentence.