TMA02 Question 2 java code