Fixed toJavaCode()

Added brackets around composite values and if statements so that it compiles
correctly. Also accounted for the "ahead(1)" that was a bodge to prevent skipped
turns; ought to fix this properly, but it will do for now.