Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Course[] commonCourses(Student one, Student two) {
- int count = 0;
- Course[] commonCourses = new Course[Math.min(one.getSchedule().length, two.getSchedule().length)];
- /*
- * if(one.getSchedule().length>two.getSchedule().length){ for (int i =
- * 0; i<two.getSchedule().length; i++){
- *
- * for(int y = 0; y < two.getSchedule()[i].getRoster().length; i++){
- *
- * if(two.getSchedule()[i].getRoster()[y].equals(one)){
- *
- * commonCourses[count++]=one.getSchedule()[i];
- *
- * } } } }
- */
- // System.out.println(one.getSchedule()[0].toString());
- for (int i = 0; i < one.getSchedule().length; i++) {
- for (int y = 0; y < two.getSchedule().length; y++) {
- if (one.getSchedule()[i] != null && two.getSchedule()[y] != null) {
- if (one.getSchedule()[i].equals(two.getSchedule()[y])
- && one.getSchedule()[i].getPeriod().equals(two.getSchedule()[y].getPeriod())) {
- commonCourses[count++] = one.getSchedule()[i];
- }
- }
- }
- }
- // Make a array of exact size and copy common courses over or return
- // null if no common courses
- Course[] toReturn;
- if (count == 0) {
- return null;
- } else {
- toReturn = new Course[count];
- for (int i = 0; i < count; i++) {
- toReturn[i] = commonCourses[i];
- }
- }
- return toReturn;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement