Advertisement
Guest User

Untitled

a guest
May 26th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. package aml.common;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class Manager {
  6.  
  7. private ArrayList <Student> students;
  8. private ActivityManager activityMngr;
  9.  
  10. public Manager()
  11. {
  12. activityMngr = new ActivityManager();
  13. }
  14.  
  15. public void addStudent(Student newSt)
  16. {
  17. students.add(newSt);
  18. }
  19.  
  20. public void removeStudent(String name, int number)
  21. {
  22. students.remove(searchStudent(name, number));
  23. }
  24.  
  25. //Didnt change this method, but you are giving the program a name and it gives you the same name back
  26. //is that supposed to be like that or supposed to return the info of said student?
  27. public String searchStudent(String name, int number)
  28. {
  29. int i = 0;
  30. while (i < students.size()) {
  31. if (name.equals(students.get(i).getName()) && (number==(students.get(i).getNumber()))){
  32. return name; // in the main if return 1 then found
  33. }
  34. i++;
  35. }
  36. return null; // if returns -1 student not found
  37. }
  38.  
  39. public void print() // prints all the details
  40. {
  41. for (Student r : students)
  42. {
  43. System.out.println("Name= " + r.getName() + "Number = " + r.getNumber() );
  44. }
  45. }
  46.  
  47.  
  48. /*public void enrollStudent(String name, int number, String category)
  49. {
  50. searchStudent(name, number);
  51. searchActivity(name, category);
  52.  
  53.  
  54. }*/
  55.  
  56.  
  57. public void enrollStudent(String name, int number, String activityName, String category)
  58. {
  59. //Searchs if student exists
  60. if(searchStudent(name, number)!=null)
  61. {
  62. //if true, seaches if activity exists
  63. if(activityMngr.searchActivity(name, category)!=null)
  64. {
  65. //since your search student doesnt return a student adress we have to search it again
  66. for(Student st : students)
  67. {
  68.  
  69. if(st.getNumber()==number)
  70. {
  71. //when it finds it it searches for activity ((IMPORTANT : activityM was made public in ActivityManager.class and instanced in this class
  72. for(Activity ac : activityMngr.activityM)
  73. {
  74.  
  75. if(ac.getName().equalsIgnoreCase(activityName))
  76. {
  77. //adds activity to student
  78. st.addStActivity(ac);
  79. //prints out success
  80. System.out.println("Success");
  81. //breaks out of this loop
  82. break;
  83. }
  84. }
  85. //breaks out of student search loop
  86. break;
  87. }
  88. }
  89. }
  90. else //case not found print this
  91. {
  92. System.out.println("Activity not found!");
  93. }
  94. }
  95. else//case Student not found print this
  96. {
  97. System.out.println("Student Not found");
  98. }
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement