An exercise in Java