Library › Coding AI › College students
Turn a UML box into a Java class stub for your team
Practice: Setting limits and rules. About 5 minutes.
About this exercise
Your team splits work by class, so you're writing the LibraryCard skeleton from the UML for teammates to fill in. Team rules: the class is public final, fields are private final with the UML names, the constructor stores loans as a defensive copy with List.copyOf(loans), there's a getter for each field and no setters, and checkout and returnBook stubbed with throw new UnsupportedOperationException("TODO"). Your course bans records and Lombok. Exactly 1 code block of at most 34 lines, under 20 words of text.
Common mistakes when you ask AI for this
- Getting it implemented. The AI writes the 5-loan check, which is Priya's task next week. Try: Say: "Stub checkout and returnBook with throw new UnsupportedOperationException(\"TODO\")."
- A record or Lombok. On Java 17 the AI may use a record or @Getter, which your course bans. Try: Add: "Plain class, no records, no Lombok."
- Missing the team rules. The AI won't make the class final or copy the list unless told, so callers can change a card's loans. Try: Add: "public final class; this.loans = List.copyOf(loans); getters only."
- Notes and javadoc. The AI adds javadoc for every method and an explanation. Try: Add: "One code block, no comments, no text."
What a strong prompt includes
- Asks for stubs
- Bans records and Lombok
- Asks for a defensive copy
- Asks for final fields
- Limits the reply
Related exercises
- Add a cron line that matches the others in a crontab (Coding AI · Product managers)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)
- Add input checks to your number guessing game (Coding AI · High school students)
- Add input validation to a Java method with exact messages (Coding AI · Software developers)
- Add labels to a signup form without rewriting the page (Coding AI · High school students)