trying to Implement the MS-PS algorithm in Java