Problems 6-10 solved in Java