java code mostly works now, just need to loop