Solution to Java Programming Exercise.