Exercise 2.1 from Liang Java Textbook 8E Comprehensive Version