68 329
Assignments Done
98,8%
Successfully Done
In November 2018

# Answer to Question #58846 in Java | JSP | JSF for Nithya

Question #58846
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.

import java.util.ArrayList;

public class Student {

ArrayList<Event>[] countEvents=new ArrayList[12];
String name;

public static void main(String[] args) {

}

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;

}
}
public class Event {
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!