How were you able to write such a large, complicated program and then give up?
You need to know how to debug the code. One way is by adding println() statements that show you where the execution goes and what values variables have at each point.
You MUST have some ideas about where the execution should go and how variables change as you go thru the code.
By printing out the trace you should be able to see where the program doesn't do what you want it to do. Then you need to look at that code and see why it does what it does.