Advertisement
Guest User

commonCourses

a guest
May 4th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. public static Course[] commonCourses(Student one, Student two) {
  2.  
  3. int count = 0;
  4. Course[] commonCourses = new Course[Math.min(one.getSchedule().length, two.getSchedule().length)];
  5.  
  6. /*
  7. * if(one.getSchedule().length>two.getSchedule().length){ for (int i =
  8. * 0; i<two.getSchedule().length; i++){
  9. *
  10. * for(int y = 0; y < two.getSchedule()[i].getRoster().length; i++){
  11. *
  12. * if(two.getSchedule()[i].getRoster()[y].equals(one)){
  13. *
  14. * commonCourses[count++]=one.getSchedule()[i];
  15. *
  16. * } } } }
  17. */
  18.  
  19. // System.out.println(one.getSchedule()[0].toString());
  20.  
  21. for (int i = 0; i < one.getSchedule().length; i++) {
  22.  
  23. for (int y = 0; y < two.getSchedule().length; y++) {
  24.  
  25. if (one.getSchedule()[i] != null && two.getSchedule()[y] != null) {
  26.  
  27. if (one.getSchedule()[i].equals(two.getSchedule()[y])
  28. && one.getSchedule()[i].getPeriod().equals(two.getSchedule()[y].getPeriod())) {
  29.  
  30. commonCourses[count++] = one.getSchedule()[i];
  31.  
  32. }
  33.  
  34. }
  35.  
  36. }
  37.  
  38. }
  39.  
  40. // Make a array of exact size and copy common courses over or return
  41. // null if no common courses
  42. Course[] toReturn;
  43. if (count == 0) {
  44. return null;
  45. } else {
  46. toReturn = new Course[count];
  47. for (int i = 0; i < count; i++) {
  48.  
  49. toReturn[i] = commonCourses[i];
  50. }
  51. }
  52.  
  53. return toReturn;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement