So I have this program that reads a Java textfile and prints out the numbers, which are electric bills. Then it finds out the maximum and prints that out along with what month the max came from. My teacher looks for efficiency of code, and I was wondering if there was an easier or possible way to factor the months of the year, instead of using an if else statement. I read about it and I'm pretty sure that Java has the months stored somewhere, but I'm not sure how to get to it. (I'm just beginning to learn java so please use basic terms/code)
My code is:
if (count == 0)
System.out.println("File had no numbers");
else {
String month="";
if (count==1) month="January";
else if (finalcount==2) month="February";
else if (finalcount==3) month="March";
else if (finalcount==4) month="April";
else if (finalcount==5) month="May";
else if (finalcount==6) month="June";
else if (finalcount==7) month="July";
else if (finalcount==8) month="August";
else if (finalcount==9) month="September";
else if (finalcount==10) month="October";
else if (finalcount==11) month="November";
else if (finalcount==12) month="December";
System.out.println("Largest Bill: "+max+ " (" +month+")");
System.out.println("Total Yearly Sum: $"+((int)sum*100)/100.0);
}
Thanks!