Simple Java CS202 solution