1- maxEvents(ArrayList<Student>): which receives array list of students and returns the name of the students who has maximum number of events.
2- sameMonth(Student s1, Student s2): which receives two objects of students and returns true if both of them have any events in the same month.
3- eventsMonth(ArrayList<Student>,int) which receives array list of students and an integer represents the month. It returns an integer represents how many students in the array list who have events at the received month.
public static String maxEvents(ArrayList<Student> students){ String nameOfStudents=""; int maxEvents=-1; for (Student student : students) { int countEvents=0; for (ArrayList<Event> events : student.countEvents) { countEvents+=events.size(); } if (countEvents>maxEvents){ maxEvents=countEvents; nameOfStudents=student.name; } else if (maxEvents==countEvents) nameOfStudents+=", "+student.name; } return nameOfStudents; }
public static boolean sameMonth(Student s1, Student s2){ for (int i = 0; i < 12; i++) { if (s1.countEvents[i].size()==s2.countEvents[i].size()){ return true; } } return false; }
public static int eventsMonth(ArrayList<Student> students,int i){ int count=0; for (Student student : students) { if (student.countEvents[i].size()!=0) count++; } return count;
Comments
Leave a comment