Esempio n. 1
0
 private boolean existsInGroup(Student st) {
   boolean result = false;
   for (Student grStudent : this.students) {
     if (grStudent != null) {
       if (grStudent.getSirname().equals(st.getSirname())
           && grStudent.getName().equals(st.getName())
           && grStudent.getGender() == st.getGender()
           && grStudent.getAge() == st.getAge()) {
         result = true;
       }
     }
   }
   return result;
 }
 private void assignStudent(Student s) {
   for (int y = 0; y < dorms.size(); y++) {
     if (s.hasRoom()) {
       break;
     }
     Dorm d = (Dorm) dorms.get(y);
     if (d.isFull()) {
       continue;
     }
     if (d.isFemaleOnly() && s.getGender() == Student.Gender.MALE) {
       continue;
     }
     int i = 0;
     while (i < d.getNumRooms()) {
       if (s.hasRoom()) {
         break;
       }
       try {
         d.getRoomByIndex(i).addResident(s);
       } catch (IllegalArgumentException e) {
       }
       i++;
     }
   }
 }
 @Test
 public void gendervalueTest() {
   System.out.println("StudentTest");
   Student instance = new Student();
   String expResult = "male";
   instance.setGender(expResult);
   String result = instance.getGender();
   assertEquals(expResult, result);
 }
 @Test
 public void nameStudentTest() {
   System.out.println("StudentTest");
   Student instance = new Student("Bill Smith", "c0123456", "male", 89.3);
   assertEquals("Bill Smith", instance.getName());
   assertEquals("c0123456", instance.getId());
   assertEquals("male", instance.getGender());
   assertEquals(89.3, instance.getGrade(), 0.0);
 }
  /**
   * Assign the set of students (presumably non-incoming-freshmen, but this is not checked) passed
   * to their dorm rooms, in a way that does not take race into account. (compare {@link
   * #assignByRace}.) As a precursor (side effect) to this, any students already existing in
   * upperclass dorms will be removed.
   */
  public void assign(Bag students) {

    emptyDorms();

    // Purge all freshmen. (We're not assigning those.)
    Bag upperclassmen = null;
    try {
      upperclassmen = (Bag) students.clone();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
    for (int x = upperclassmen.size() - 1; x >= 0; x--) {
      Student s = (Student) upperclassmen.get(x);
      if (s.getGrade() < 2) {
        upperclassmen.remove(s);
      }
    }

    for (int x = 0; x < upperclassmen.size(); x++) {
      Student s = (Student) upperclassmen.get(x);
      if (s.getGrade() < 2) {
        // We're only assigning upperclassmen here.
        continue;
      }
      s.leaveRoom();
      for (int y = 0; y < dorms.size(); y++) {
        if (s.hasRoom()) {
          break;
        }
        Dorm d = (Dorm) dorms.get(y);
        if (d.isFull()) {
          continue;
        }
        if (d.isFemaleOnly() && s.getGender() == Student.Gender.MALE) {
          continue;
        }
        int i = 0;
        while (i < d.getNumRooms()) {
          if (s.hasRoom()) {
            break;
          }
          try {
            d.getRoomByIndex(i).addResident(s);
          } catch (IllegalArgumentException e) { // System.out.println(e);
          }
          i++;
        }
      }
    }

    // Error testing to see if there are upperclassmen who don't have a
    //  room/dorms that aren't full
    // int q=0;
    for (int x = 0; x < upperclassmen.size(); x++) {
      Student s = (Student) upperclassmen.get(x);
      if (!s.hasRoom()) {
        System.out.println(s + " has no upperclass dorm room!");
      }
    }
  }
  /**
   * Assign the set of students (presumably non-incoming-freshmen, but this is not checked) students
   * passed to their dorm rooms, in a way that <i>does</i> take race into account. (compare {@link
   * #assign}.) Minorities will have a higher probability of rooming with other minorities than they
   * would otherwise have had. As a precursor (side effect) to this, any students already existing
   * in upperclass dorms will be removed.
   */
  public void assignByRace(Bag upperclassmen) {
    emptyDorms();
    boolean foundRoomie;
    for (int x = 0; x < upperclassmen.size(); x++) {
      foundRoomie = false;
      Student s = (Student) upperclassmen.get(x);
      // need to leave current room so that they can get a new room
      s.leaveRoom();
      if (s.getRace() == Student.Race.MINORITY) {
        double rollDice = Sim.instance().random.nextDouble();
        if (rollDice < Sim.PROB_DUAL_MINORITY) {
          for (int m = 0; m < upperclassmen.size(); m++) {
            Student r = (Student) upperclassmen.get(m);
            // if the potential roommate is the same gender, is a
            //  minority, and has no room
            if (r.getId() == s.getId()) {
              continue;
            }
            if (r.getRace() == Student.Race.MINORITY
                && r.getGender() == s.getGender()
                && !(r.hasRoom())
                && !(s.hasRoom())) {
              // find a room that is completely empty
              foundRoomie = true;
              for (int y = 0; y < dorms.size(); y++) {
                Dorm d = (Dorm) dorms.get(y);
                if (d.isFull()) {
                  continue;
                }
                if (d.isFemaleOnly() && s.getGender() == Student.Gender.MALE) {
                  continue;
                }
                int i = 0;
                while (i < d.getNumRooms()) {
                  if (s.hasRoom() && r.hasRoom()) {
                    break;
                  }
                  try {
                    if (d.getRoomByIndex(i).isEmpty()) {
                      try {
                        d.getRoomByIndex(i).addResidents(s, r);
                      } catch (IllegalArgumentException e) {
                        System.out.println(e);
                      }
                    }
                  } catch (IllegalArgumentException e) {
                  }
                  i++;
                }
              }
              if (!s.hasRoom()) {
                // no empty room has been found to put these
                // students in; just assign them normally
                assignStudent(s);
              }
              if (!r.hasRoom()) {
                assignStudent(r);
              }
            }
          }
          if (foundRoomie == false) {
            // no same-minority, same-sex, roomless roommate found
            assignStudent(s);
          }
        } else {
          // dice roll not under PROB_DUAL_MINORITY
          assignStudent(s);
        }

      } else {
        // not a minority, assign normally
        assignStudent(s);
      }
    }
  }
Esempio n. 7
0
  /**
   * Creates a small window for editing student information
   *
   * @param window Parent window
   * @param student Student to edit.
   */
  public StudentInfoEditor(StudentsListTab window, Student student) {
    this.window = window;
    this.student = student;
    this.setTitle(student.getFirstName() + " " + student.getLastName());

    this.tabs = new JTabbedPane();

    this.avoidingTable = makeTable(student);
    this.scrollbar = new JScrollPane(this.avoidingTable);

    /*
     * Separation Tab
     */
    JPanel buttonsPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    JButton newStudentButton = new JButton("New");
    newStudentButton.setActionCommand("New Student");
    newStudentButton.addActionListener(this);
    buttonsPane.add(newStudentButton);

    JButton delStudentButton = new JButton("Delete");
    delStudentButton.setActionCommand("Delete Student");
    delStudentButton.addActionListener(this);
    buttonsPane.add(delStudentButton);

    JPanel separationPanel = new JPanel(new BorderLayout());
    separationPanel.add(scrollbar, BorderLayout.CENTER);
    separationPanel.add(buttonsPane, BorderLayout.PAGE_END);

    /*
     * Information Editing Tab contents
     */

    /*
     * Name and student ID text fields for setting those of a student.
     */
    JPanel studentIDSetter = new JPanel(new FlowLayout(FlowLayout.LEFT));
    JLabel studentIDLabel = new JLabel("Student ID: ");
    this.studentIDField = new JTextField(Integer.toString(student.getStudentID()));
    this.studentIDField.setColumns(5);
    studentIDSetter.add(studentIDLabel);
    studentIDSetter.add(studentIDField);

    JPanel firstNameSetter = new JPanel(new FlowLayout(FlowLayout.LEFT));
    JLabel firstNameLabel = new JLabel("First: ");
    this.firstNameField = new JTextField(student.getFirstName());
    this.firstNameField.setColumns(8);
    firstNameSetter.add(firstNameLabel);
    firstNameSetter.add(firstNameField);

    JPanel lastNameSetter = new JPanel(new FlowLayout(FlowLayout.LEFT));
    JLabel lastNameLabel = new JLabel("Last: ");
    this.lastNameField = new JTextField(student.getLastName());
    this.lastNameField.setColumns(8);
    lastNameSetter.add(lastNameLabel);
    lastNameSetter.add(lastNameField);

    /*
     * Box to force assigned seating
     */
    JPanel assignedSeatSetter = new JPanel(new FlowLayout(FlowLayout.LEFT));
    JLabel assignedSeatLabel = new JLabel("Assigned Seat");
    this.assignedSeatField = new JTextField();
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < this.window.currentClass.getQuadrants().get(i).getSize(); j++) {
        Desk desk = this.window.currentClass.getQuadrants().get(i).getDesk(j);
        if (desk.isEditable() == false && desk.getOccupyingStudent().equals(student)) {
          switch (i) {
            case 0:
              this.assignedSeatField = new JTextField(Integer.toString(j + 1));
              break;
            case 1:
              this.assignedSeatField = new JTextField(Integer.toString(j + 11));
              break;
            case 2:
              this.assignedSeatField = new JTextField(Integer.toString(j + 23));
              break;
          }
        }
      }
    }
    this.assignedSeatField.setColumns(2);
    assignedSeatSetter.add(assignedSeatLabel);
    assignedSeatSetter.add(assignedSeatField);

    /*
     * Box to set the race of a student.
     */
    JPanel raceSetter = new JPanel(new FlowLayout(FlowLayout.LEFT));
    JLabel raceNameLabel = new JLabel("Race: ");
    this.raceSelection =
        new JComboBox<String>(
            new String[] {
              "White", "Asian", "AfricanAmerican", "Latino", "PacificIslander", "Other"
            });
    this.raceSelection.setSelectedItem(student.getRace().toString());
    raceSetter.add(raceNameLabel);
    raceSetter.add(raceSelection);

    /*
     * Box to set the Gender of a student
     */
    JPanel genderSetter = new JPanel(new FlowLayout(FlowLayout.LEFT));
    JLabel genderLabel = new JLabel("Gender: ");
    this.genderSelection = new JComboBox<String>(new String[] {"Male", "Female", "Other"});
    this.genderSelection.setSelectedItem(student.getGender().toString());
    genderSetter.add(genderLabel);
    genderSetter.add(genderSelection);

    /*
     * Bottom button pane with save/cancel buttons
     */
    JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
    JButton saveChanges = new JButton("Save");
    saveChanges.addActionListener(this);
    saveChanges.setActionCommand("Save");

    JButton cancelChanges = new JButton("Cancel");
    cancelChanges.addActionListener(this);
    cancelChanges.setActionCommand("Cancel");

    buttonPane.add(saveChanges);
    buttonPane.add(cancelChanges);

    JPanel comboboxPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
    comboboxPane.add(genderSetter);
    JPanel informationPanel = new JPanel();
    informationPanel.setLayout(new GridLayout(5, 2));
    informationPanel.add(studentIDSetter);
    informationPanel.add(assignedSeatSetter);
    informationPanel.add(firstNameSetter);
    informationPanel.add(lastNameSetter);
    informationPanel.add(genderSetter);
    informationPanel.add(raceSetter);
    informationPanel.add(new JPanel());
    informationPanel.add(buttonPane);

    tabs.addTab("Information", null, informationPanel);
    ;
    tabs.addTab("Separation", null, separationPanel);

    this.add(tabs, BorderLayout.CENTER);

    this.setResizable(false);
    this.setSize(400, 320);
    this.setLocationRelativeTo(null);
    this.setVisible(true);
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  }