Completed code for chapter 1

This is a straight Java to Scala port of the chapter 1 code.