@Test
  public void test1() throws Exception {

    Student denise = studentHome.create("823", "Denise Smith");

    Course power = courseHome.create("220", "Power J2EE Programming");

    Enroller enroller = enrollerHome.create();
    enroller.enroll("823", "220");
    enroller.enroll("823", "333");
    enroller.enroll("823", "777");
    enroller.enroll("456", "777");
    enroller.enroll("388", "777");

    System.out.println(denise.getName() + ":");
    ArrayList courses = denise.getCourseIds();
    Iterator i = courses.iterator();
    while (i.hasNext()) {
      String courseId = (String) i.next();
      Course course = courseHome.findByPrimaryKey(courseId);
      System.out.println(courseId + " " + course.getName());
    }

    System.out.println();

    Course intro = courseHome.findByPrimaryKey("777");
    System.out.println(intro.getName() + ":");
    courses = intro.getStudentIds();
    i = courses.iterator();
    while (i.hasNext()) {
      String studentId = (String) i.next();
      Student student = studentHome.findByPrimaryKey(studentId);
      System.out.println(studentId + " " + student.getName());
    }
  }
  public boolean compatible(Course other) {
    /* Check that teachers are not the same */
    if (this.getTeacher().equals(other.getTeacher())) return false;
    /* Check that the union of the two courses' students is empty */
    for (Student s : this) if (other.contains(s)) return false;

    return true;
  }
Beispiel #3
0
  public void addEdge(Course source, Course target) {

    if (this.edges.containsKey(source.getName())) {
      this.edges.get(source.getName()).put(target.getName(), target);
    } else {
      this.edges.put(source.getName(), new HashMap<String, Course>());
      this.edges.get(source.getName()).put(target.getName(), target);
    }
  }
Beispiel #4
0
 public void buildCourseList(LinkedList<Course> courseList) {
   ListIterator<Course> iterator = courseList.listIterator();
   while (iterator.hasNext()) {
     Course tempCourse = iterator.next();
     String professor = getLastName() + getFirstName().substring(0, 1);
     if (tempCourse.getProfessor().equalsIgnoreCase(professor)) {
       courses.add(tempCourse);
     }
   }
 }
  /* Adds a prerequisite for a course.  First checks that the new prerequisite
   * will not introduce a circular dependency.
   * Throws InvalidCourseNumberException if the course number or prerequisite number are not positive.
   * Throws NoSuchElementException if either course does not exist in the database.
   * Throws CircularPreREquisiteException if adding the preqrequisite would introduce a circular dependency.
   * Returns true if prerequisite added, false if it already existed. */
  boolean validateAndAddPreReq(int courseNumber, int newPreReqNumber)
      throws InvalidCourseNumberException, NoSuchElementException, CircularPreRequisiteException {
    Course course = getCourse(courseNumber);
    Course newPreReq = getCourse(newPreReqNumber);

    if (path(newPreReq, courseNumber)) {
      throw new CircularPreRequisiteException();
    }

    return (course.addPreReq(newPreReq));
  }
 public void run() {
   for (Course course : Course.values()) {
     Food food = course.randomSelection();
     try {
       waitPerson.placeOrder(this, food);
       // Blocks until course has been delivered:
       print(this + "eating " + placeSetting.take());
     } catch (InterruptedException e) {
       print(this + "waiting for " + course + " interrupted");
       break;
     }
   }
   print(this + "finished meal, leaving");
 }
  /* Returns the course associated with this course number.
   * Throws InvalidCourseNumberException if the course number is not positive.
   * Throws NoSuchElementException if the course does not exist in the database. */
  Course getCourse(int queryCourseNumber)
      throws InvalidCourseNumberException, NoSuchElementException {
    ListIterator<Course> itr = courses.listIterator(0);
    Course course;

    if (queryCourseNumber <= 0) {
      throw new InvalidCourseNumberException();
    }

    while (itr.hasNext()) {
      course = itr.next();
      if (course.getCourseNumber() == queryCourseNumber) {
        return (course);
      }
    }
    throw new NoSuchElementException();
  }
  /* Determines whether a course sequence is valid in the sense that all prerequisites
   * are satisfied when each course is taken.  This method uses the temporary
   * variable 'visited' associated with each course to efficiently validate the sequence.
   * Throws InvalidCourseNumberException if any of the course numbers are not positive.
   * Throws NoSuchElementException if any of the courses do not exist in the database.
   */
  boolean validateCourseSequence(int[] sequence)
      throws InvalidCourseNumberException, NoSuchElementException {
    ListIterator<Course> itr = courses.listIterator();
    Course course, next;
    boolean visited = true;
    for (; itr.hasNext(); ) {

      next = itr.next();
      next.setVisited(!visited);

      if (next.getCourseNumber() <= 0) {
        throw new InvalidCourseNumberException("The course number is invalid");
      }
    }
    for (int i = 0; i < sequence.length; i++) {
      course = getCourse(sequence[i]);

      if (course.canTakeCourse()) {
        course.setVisited(visited);
      } else {
        visited = false;
        return visited;
      }
    }
    return visited;
  }
Beispiel #9
0
  /** @param courseList Create all courses based on text file input */
  public static void populateCourses(LinkedList<Course> courseList) {

    Scanner inputStream = null;

    // open text file
    try {
      inputStream = new Scanner(new FileInputStream("courses.txt"));
    } catch (FileNotFoundException e) {
      JOptionPane.showMessageDialog(null, "The file \"courses.txt\" could not be found");
      JOptionPane.showMessageDialog(null, "The system will now exit");
      System.exit(0);
    }

    // pull line of text to generate a course
    while (inputStream.hasNextLine()) {
      String s1 = inputStream.nextLine();
      // locate course name
      int courseNameStart = (s1.indexOf("-") + 1);
      int courseNameEnd = (s1.indexOf(","));
      String courseName = s1.substring(courseNameStart, courseNameEnd);
      // locate course text
      int courseTextStart = (s1.indexOf(",", courseNameEnd) + 1);
      int courseTextEnd = (s1.indexOf(",", courseTextStart));
      String courseText = (s1.substring(courseTextStart, courseTextEnd));
      // locate text stock
      int textStockStart = (s1.indexOf(",", courseTextStart) + 1);
      int textStock = Integer.parseInt(s1.substring(textStockStart));

      // create course from info
      Course aCourse = new Course(courseName);
      aCourse.setCourseText(courseText);
      aCourse.setTextStock(textStock);

      // add course to list
      courseList.add(aCourse);
    }
  }
  // Deze method maakt activities aan
  public List<Activity> createActivity(
      Course course,
      Integer activitiesPerWeek,
      Integer maxNumberStudents,
      String nameLectureType,
      boolean hoorcollege) {
    List<Activity> activities = new ArrayList<>();
    // Algoritme om (werk)groepen aan te maken
    for (int i = 1; i <= activitiesPerWeek; i++) {
      if (!hoorcollege && activitiesPerWeek >= 1) {

        // Verdeelt studenten over groepen als er meer studenten zijn dan capaciteit van 1
        // (werk)groep
        if (course.courseStudents.size() > maxNumberStudents) {
          int numberGroups =
              (int)
                  Math.ceil(((double) course.courseStudents.size()) / ((double) maxNumberStudents));
          int numberStudentsGroup =
              (int) Math.ceil(((double) course.courseStudents.size()) / ((double) numberGroups));

          course.numberOfGroups = numberGroups;
          int j;
          for (j = 1; j < numberGroups; j++) {
            List<Student> studentsWorkGroup =
                course.courseStudents.subList(
                    (j - 1) * numberStudentsGroup, j * numberStudentsGroup);
            Activity workGroup = new Activity(course, nameLectureType, i, j, studentsWorkGroup);
            activities.add(workGroup);
          }
          List<Student> studentsWorkGroup =
              course.courseStudents.subList(
                  numberStudentsGroup * (j - 1), course.courseStudents.size());
          Activity workGroup = new Activity(course, nameLectureType, i, j, studentsWorkGroup);
          activities.add(workGroup);

        }
        // Maakt 1 (werk)groep
        else {
          Activity subGroup = new Activity(course, nameLectureType, i, 1, course.courseStudents);
          activities.add(subGroup);
        }
        // Maakt 1 hoorcollege
      } else if (hoorcollege && activitiesPerWeek >= 1) {
        Activity hoorCollege = new Activity(course, nameLectureType, i, 1, course.courseStudents);
        activities.add(hoorCollege);
      }
    }
    return activities;
  }
Beispiel #11
0
  public static void addCourse(LinkedList<Course> courseList) {
    JOptionPane.showMessageDialog(null, "Welcome to the admin menu.\nLet's add new courses!");
    String courseName = "";
    String courseText = "";
    int textStock = -1;

    Course aCourse = new Course();
    do {
      do {
        courseName =
            JOptionPane.showInputDialog(
                "Please enter the course name in the format ITXXX (where XXX are numbers");
        if (!aCourse.setCourseName(courseName)) {
          JOptionPane.showMessageDialog(
              null,
              "May be already in use or in incorrect format.\nThe course name must be atleast 5 characters long in this format: ITXXX",
              "Invalid Course Name",
              JOptionPane.ERROR_MESSAGE);
        }
      } while (!(aCourse.setCourseName(courseName)));

      do {
        courseText =
            JOptionPane.showInputDialog("Please enter the textbook name for " + courseName);
        if (!aCourse.setCourseText(courseText)) {
          JOptionPane.showMessageDialog(
              null, "Invalid course text", "Invalid Course Text", JOptionPane.ERROR_MESSAGE);
        }
      } while (!(aCourse.setCourseText(courseText)));

      do {
        try {
          textStock =
              Integer.parseInt(
                  JOptionPane.showInputDialog("Enter the number of the books in stock"));
        } catch (NumberFormatException e) {
          JOptionPane.showMessageDialog(
              null, "The number of books in stock must be a numerical value");
        }
      } while ((!aCourse.setTextStock(textStock)));

      courseList.add(aCourse);
    } while (JOptionPane.showConfirmDialog(null, "addAnother") == 0);
  }
 /* private method that checks for a path from newCourse to the course with
  * number given by startCourseNumber */
 private boolean path(Course newCourse, int startCourseNumber) {
   // iterator over the elements
   ListIterator<Course> iterator = newCourse.preReqIterator();
   Course preReq;
   // to check path whether valid or not
   boolean check = false;
   for (; iterator.hasNext() & !check; ) {
     preReq = iterator.next(); // next element
     preReq.setVisited(!check); // to prevent double iteration
     if (preReq.getCourseNumber() == startCourseNumber && preReq.getVisited() == true) {
       check = true;
       return check;
     } else if (preReq.getVisited() == false) {
       check = path(preReq, startCourseNumber);
     }
     // ************************playing around***************************************//
     else {
       System.out.println("The system has no idea. Just Kidding around!!!!!!!!!!!!");
     }
     // ***********************hope you like it.LOL**********************************//
   }
   return check;
 }
Beispiel #13
0
 public static Number randomGrade(Course course, int min, int max) {
   return course.isGradeInteger()
       ? Student.randomIntegerGrade(min, max)
       : randomDoubleGrade(min, max);
 }
Beispiel #14
0
 public static Number randomGrade(Course course) {
   return course.isGradeInteger() ? Student.randomIntegerGrade() : randomDoubleGrade();
 }
Beispiel #15
0
  public void addNode(Course course) {

    if (!this.nodes.containsKey(course.getName())) {
      this.nodes.put(course.getName(), course);
    }
  }
Beispiel #16
0
  /**
   * Prompt student with list of courses and add each on based on selection to their list of courses
   *
   * @param allCourses
   * @param aStudent
   */
  public static void menu(LinkedList<Course> courseList, User aUser, LinkedList<User> userList) {
    int selection = -1;
    final int MAX_COURSES = 7;
    boolean more;

    // send user if admin to add course
    Student aStudent = new Student();
    if (aUser instanceof Student) {
      aStudent = (Student) aUser;
      String menuPrompt =
          "Welcome to the GMU IT Bookstore!"
              + "\nPlease enter the number that corresponds to one of your classes";
      for (int i = 0; i < courseList.size(); i++) {
        Course aCourse = courseList.get(i);
        menuPrompt += "\n" + (i + 1) + ") " + aCourse.getCourseName();
      }

      do {
        do {
          try {
            selection = Integer.parseInt(JOptionPane.showInputDialog(menuPrompt));

            if (selection > courseList.size() || selection <= 0) {
              throw new IllegalArgumentException();
            }
          } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(
                null, "Invalid entry, please enter number associated with course");
            selection = -1;
          } catch (IllegalArgumentException e) {
            JOptionPane.showMessageDialog(null, "Invalid Selection. Try again.");
            selection = -1;
          }

        } while (selection > courseList.size() || selection <= 0);

        // add a course to student list of courses if its not already added to student's courses
        if (aStudent.getCourseList().contains(courseList.get(selection - 1))) {
          JOptionPane.showMessageDialog(null, "You have already ordered this book");
        } else if (aStudent.getCourseList().size() >= MAX_COURSES) {
          JOptionPane.showMessageDialog(
              null,
              "You have already registered " + MAX_COURSES + " courses, the max number allowed");
          break;
        } else {
          if (courseList.get(selection - 1).getTextStock() < 1) {
            JOptionPane.showMessageDialog(
                null, "This book is backordered and will take extra processing time");
          }
          Course aCourse = (courseList.get(selection - 1));
          aStudent.addCourse(aCourse);
          JOptionPane.showMessageDialog(
              null, courseList.get(selection - 1).getCourseText() + " Has been added to your cart");
        }

        // prompt student if they would like to continue entering courses
        int reply =
            JOptionPane.showConfirmDialog(
                null, "Do you have another class to enter?", "title", JOptionPane.YES_NO_OPTION);
        if (reply == 1) {
          more = false;
        } else {
          more = true;
        }
      } while (more && (aStudent.getCourseList().size() <= MAX_COURSES));

      // Give confirmation of order
      JOptionPane.showMessageDialog(null, "Your order has been entered\n");
    } else {
      // Admin tempAdmin;
      addCourse(courseList);
    }

    // return user to login screen
    login(userList, courseList);
  }
Beispiel #17
-48
  // This method deletes a chosen course from the existing student's schedule if such a course can
  // be found.
  // It takes in a Course object for the corresponding course and returns no value.
  // It outputs an error message if there is no such course found in the student's existing
  // schedule.
  public void deleteChosenCourse(Course deletedCourse) {
    // This initializes a boolean to be false to assume that there is such a course yet to be found
    // in the student's
    // existing schedule.
    boolean found = false;

    // This loops through the student's existing schedule to find the course.
    for (int i = 0; i < schedule.getCourseChosen().size() && !found; i++) {
      Course temCourse = schedule.getCourseChosen().get(i);
      if (temCourse.getCourseCode() == deletedCourse.getCourseCode()) {
        found = true;
        // This deletes the selected course by issuing the value of the course to be null.
        schedule.getCourseChosen().remove(i);
        System.out.println("The course is removed from the student's schedule.");
      }
    }

    // This outputs an error message if there is no such a course in the student's existing
    // schedule.
    if (!found) {
      System.out.println("Sorry. The student did not select this course.");
      System.out.println("No courses can be deleted.");
    }
  }