Skip to content

This is the updated Version#22

Open
makikovaughan wants to merge 3 commits intoroesnera:mainfrom
makikovaughan:main
Open

This is the updated Version#22
makikovaughan wants to merge 3 commits intoroesnera:mainfrom
makikovaughan:main

Conversation

@makikovaughan
Copy link

What I have modified:
In Student.java
Initially I thought I had to use approvedCourses to add the course information.
So, I added courses.add(course);
Also, I added if statement.
public void enrollToCourse(Course course )
{
    //TODO implement this method
    if(!(isAttendingCourse(course.getCode()))) {
        //Initially I did correctly. I overthought add all registered courses to approvedCourses.
        //Modified back again
        courses.add(course);

        //Used for isAttendingCourse
        registerApprovedCourse(course);
    }
    else {
        System.out.println("The student has been enrolled");
    }
}
 
 
In StudentServices.java
I created a method to be able to print the courses, but reflected the duplicate courses.
 
public void addEnrollStudents(String studentId, Course course) {

    if ( (enrolledStudents.containsKey( studentId ) ))
    {
        ArrayList courseList =  enrolledStudents.get(studentId);
        System.out.println("CourseList" + courseList);

        //For avoiding ConcurrentModificationException,used for loop
        boolean flag = false;
       for(int i = 0; i < courseList.size();  i++) {
            if (courseList.get(i).getCode().equals(course.getCode())) {
                flag = true;
            }
        }
       if(!(flag)) {
           enrolledStudents.get(studentId).add( course );
       }
    }
    else {
        enrolledStudents.put( studentId, new ArrayList<>() );
        enrolledStudents.get(studentId).add( course );
    }

}
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant