work on question 4 of java assignment