written in java for algorithms class