Part 7 of 7 · 2 min read
Exercises
Easy
Easy 1: Run it (20 minutes)
Put the code from section 4 into one file with a main method that repeats the short run described there. Compile and run it.
Done when: the output shows "room is taken" and then id B2.
Hint
Records need Java 16 or newer.
Easy 2: One sentence each (20 minutes)
Write one sentence for the job of each of the four classes. Split any class that needs two "and"s.
Done when: four sentences.
Hint
A class that does two jobs needs two names.
Easy 3: Edge case table (20 minutes)
Fill the edge case table for a parking lot.
Done when: six rows with a specific case in each.
Hint
Think of a full lot, an unknown ticket and two cars at the gate.
Medium
Medium 1: Free rooms (30 minutes)
Add List<Room> findFreeRooms(List<Room> rooms, TimeSlot slot, int people) to the service.
Done when: a method that compiles and a test with three rooms.
Hint
Reuse the overlap check on each room's active bookings.
Medium 2: Test list to code (30 minutes)
Turn the five-line test list into five checks in a main method that print PASS or FAIL.
Done when: five lines of output, all PASS.
Hint
Catch the expected exceptions in the test.
Medium 3: Time yourself (30 minutes)
Solve "Design a vending machine" up to step 3 in 22 minutes. Record the minutes for each step.
Done when: a list of steps with real minutes.
Hint
Stop at the diagram, and do not code.
Hard
Hard 1: Whole method on a new prompt (45 minutes)
Apply all five steps to "Design a library management system". Produce requirements, entities, a class diagram, code for borrow and return, and ten edge cases.
Done when: one document with the five parts.
Hint
Borrow needs a limit and a due date.
Hard 2: Make it safe (45 minutes)
Make book safe for two threads, with the smallest change possible. Explain why your change works.
Done when: a changed method and a paragraph on the race it removes.
Hint
Make the check and the add one critical section.
Hard 3: Change request drill (50 minutes)
Handle three change requests on the room system: repeat weekly, manager approval, and a maximum of 2 hours per user per day. For each, list the classes that change.
Done when: a three-row table of changes with the smallest set of classes.
Hint
A new rule often goes in a new class, not in an old one.