Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. private static Student processStudent(String nextLine) {
  2. Scanner lineScanner = new Scanner(nextLine);
  3. try {
  4. lineScanner.useDelimiter(",");
  5. String firstName = lineScanner.next();
  6. String lastName = lineScanner.next();
  7. String id = lineScanner.next();
  8. String email = lineScanner.next();
  9. String password = lineScanner.next();
  10. int maxCredits = lineScanner.nextInt();
  11. Student s = new Student(firstName, lastName, id, email, password, maxCredits);
  12. while(lineScanner.hasNext()){
  13. Course c = CourseManager.getInstance().getCourseByName(lineScanner.next());
  14. if(c == null){
  15. lineScanner.close();
  16. throw new IllegalArgumentException();
  17. }
  18. if(!s.canAddCourse(c)){
  19. lineScanner.close();
  20. throw new IllegalArgumentException();
  21. }
  22. if(s.canAddCourse(c)){
  23. s.addCourse(c);
  24. // lineScanner.close();
  25. }
  26. }
  27. lineScanner.close();
  28. return s;
  29. } catch(NoSuchElementException e) {
  30. lineScanner.close();
  31. throw new IllegalArgumentException();
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement