code by chapter for http://introcs.cs.princeton.edu/java/home/