THE ATHENA LIBRARY
Java Lab Workbook
CS 220 Teaching Team practice set
Lab 3
Building classes
Implement a Book class with private fields title, author and copiesAvailable. Provide a constructor, a borrow() method that refuses to drop below zero, and a toString() override.
Write three unit tests: a successful borrow, a refused borrow, and a check that toString() includes the title.
Reflection: which method protects the class invariant, and why should copiesAvailable not have a public setter?
Fictional educational sample written for the Athena demo · Page 21 of 120.
50%saved