import java.io.FileNotFoundException; import java.io.FileReader; import java.util.LinkedList; import java.util.ListIterator; import java.util.Scanner; public class RegistrationActions { public LinkedList Registration() { LinkedList students = Student.readStudents(); try { Scanner actions = new Scanner(new FileReader("registration.txt")); String toDo; int stuNum; while (actions.hasNext()) { ListIterator mark = students.listIterator(); String hold = actions.next(); Student stu = null; int test = Integer.parseInt(hold); while (mark.hasNext()) { stu = mark.next(); stuNum = stu.getStudentNumber(); // if the student is found if (test == stuNum) break; } toDo = actions.next(); if (toDo.equalsIgnoreCase("A")) { ListIterator alreadyHave = RegistrationSystem .getAllOfferings().listIterator(); boolean found = false; String holding = actions.next(); short ref = Short.parseShort(holding); for (int i = 0; i < stu.getNumberCourses();i++) { Offering course = alreadyHave.next(); short check = course.reference; if (check == ref) { found = true; stu.addCourse(course); break; } } if (found == false) { Offering course = new Offering(ref); RegistrationSystem.getAllOfferings().addLast( course); stu.addCourse(course); System.out.println("Course added"); // break; } } else if (toDo.equalsIgnoreCase("D")) { Offering course = new Offering(); String holder = actions.next(); short ref = Short.parseShort(holder); course.setReference(ref); stu.dropCourse(course); System.out.println("Course dropped"); break; } } } catch (FileNotFoundException e) { System.out.println("Registration File not found."); System.exit(1); } return students; } }