finished code example for section7, chapter10, GatheringWrite.java