It seems like ifs are missing brackets ? (That's why most devs prefer to always use brackets) Probably x1 and x2 should be initialized to this.x1. together with using else if it would simplify the code.