I am working on this piece of code. Here is the pseudo code of what I want:
a.check if the size of the partitions (which is a list) is 0.
b.if the size of the sections is 0, then automatically enrolls the student in the section by calling section.add (newSection)
c.else, if the size of the partitions is not zero, check for conflicts with the schedule
d. if there are no conflicts, then write the student to the section by calling section.add (newSection)
e.else do nothing
Java keeps throwing the error "java.util.concurrentmodificationexception" on me. I know I should not resize the ArrayList when moving the list, because it will change the iterator. Is there any other way to solve this problem ?: D
Many thanks. Your help is much appreciated. :)
public String enrollsTo(Section newSection){ StringBuffer result = new StringBuffer(); String resultNegative = "Failed to enroll in this section."; String resultPositive = "Successfully enrolled in section: " + newSection.getSectionName() + "."; int previousSectionSize = sections.size(); if(this.sections.isEmpty()){ this.sections.add(newSection); result.append(resultPositive); }else{ for(Iterator<Section> iterator = sections.iterator(); iterator.hasNext() ; ){ Section thisSection = iterator.next(); if(thisSection.conflictsDayWith(newSection)==false && thisSection.conflictsTimeWith(newSection)==false){ this.sections.add(newSection);
ν©νμ
source share