This assignment asks you to write and compile a simple, but complete class specification. You should also write a test driver, a main() method, that demonstrates that it functions correctly. The goal here is to reinforce your understanding of the object-oriented approach to software development as well as to introduce you to Exceptions.
Please think carefully about not only where the exceptional conditions can occur, but also where the Exceptions should be defined, and where they are best handled -- and what that means for the access-specifier of each of the Exception classes. facility.
The Textbook class
Please implement a class specification for a class that models aspects of a textbook might be useful for an on-line ordering system:
- The textbook's title. This shall be set at initalization and accessible, but unchangeable.
- The textbook's author. This shall be set at initalization and accessible, but unchangeable.
- The textbook's number of pages. This shall be set at initalization and accessible, but unchangeable.
- The textbook's price. It may be set at initalization (or not) and can be changed later. It is also accessible.
- Reader's comments. These can be augmented, but not changed. In other words, comments can be added, but not removed or changed.
- The now-routine toString() and equals() methods
- A Textbook cannot have a negative price or negative number of pages. An attempt to assign these types of attributes to a Textbook should result in a NegativePagesException, or a NegativePriceException. These conditions, and the proper generation of Exceptions, should be tested within your test driver (thing tr's and catch'es).