Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aml.common;
- import java.util.ArrayList;
- public class Manager {
- private ArrayList <Student> students;
- private ActivityManager activityMngr;
- public Manager()
- {
- activityMngr = new ActivityManager();
- }
- public void addStudent(Student newSt)
- {
- students.add(newSt);
- }
- public void removeStudent(String name, int number)
- {
- students.remove(searchStudent(name, number));
- }
- //Didnt change this method, but you are giving the program a name and it gives you the same name back
- //is that supposed to be like that or supposed to return the info of said student?
- public String searchStudent(String name, int number)
- {
- int i = 0;
- while (i < students.size()) {
- if (name.equals(students.get(i).getName()) && (number==(students.get(i).getNumber()))){
- return name; // in the main if return 1 then found
- }
- i++;
- }
- return null; // if returns -1 student not found
- }
- public void print() // prints all the details
- {
- for (Student r : students)
- {
- System.out.println("Name= " + r.getName() + "Number = " + r.getNumber() );
- }
- }
- /*public void enrollStudent(String name, int number, String category)
- {
- searchStudent(name, number);
- searchActivity(name, category);
- }*/
- public void enrollStudent(String name, int number, String activityName, String category)
- {
- //Searchs if student exists
- if(searchStudent(name, number)!=null)
- {
- //if true, seaches if activity exists
- if(activityMngr.searchActivity(name, category)!=null)
- {
- //since your search student doesnt return a student adress we have to search it again
- for(Student st : students)
- {
- if(st.getNumber()==number)
- {
- //when it finds it it searches for activity ((IMPORTANT : activityM was made public in ActivityManager.class and instanced in this class
- for(Activity ac : activityMngr.activityM)
- {
- if(ac.getName().equalsIgnoreCase(activityName))
- {
- //adds activity to student
- st.addStActivity(ac);
- //prints out success
- System.out.println("Success");
- //breaks out of this loop
- break;
- }
- }
- //breaks out of student search loop
- break;
- }
- }
- }
- else //case not found print this
- {
- System.out.println("Activity not found!");
- }
- }
- else//case Student not found print this
- {
- System.out.println("Student Not found");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement