java code for hw 5 implemented, not working