I need to display the names of people whose birthday occur in a certain month. The name of the month must still appear, even if there was no birthday that month. (All info is extracted from a text file)
Eg.
January:
Sam
Kate
February:
//no birthday in Feb
March:
Fred
etc
Method:
private Employee[] arr = new Employee[8];//Employee class
public String birthdays() throws ParseException{
String list = "";
for(int i = 0; i < arr.length; i++){
String month = arr[i].getDob().substring(3, 5);
if(month.equals("01")){
System.out.println("Jan" + "\n" + arr[i].getName() + " " + arr[i].getSurname());
}else if(month.equals("02")){
System.out.println("Feb" + "\n" + arr[i].getName() + " " + arr[i].getSurname());
}//if
}//for
return list;
}//birthdays
The problem is that it seems like that repeating the "if statement" is not really good coding and that if a birthday does not occur in a certain month, the name of the month will not appear.
How would I solve this?