How have you tried debugging the code to see what it is doing?
Try adding some calls to the println() method that prints out the value of all variables as their value is changed.
Also print out the...