finished the java code