simplify_fraction, written in java