Do you have the algorithm for solving the problem? How would you do it manually?
Write the steps down in pseudo code to work out the logic and then convert the pseudo code to java code.

It'll...