Example and exercise from Book: Thinking in Java (Second Edition)