roster.java

来自「< ProJavaProgrammingSecondEdition>」· Java 代码 · 共 39 行

JAVA
39
字号
import java.util.Vector;

public class Roster {

  protected int capacity;
  protected Vector students;

  public Roster(int max) {
    capacity = max;
    students = new Vector();
  }

  /**
   *  Enrolls the student in this course.
   *
   *  @param  name    Name of the student to enroll.
   */
  public void enrollStudent(String name) {
    students.addElement(name);
  }

  /**
   *  Attempts to enroll a student in this course. The student is only
   *  added if the capacity limit for the course has not been reached.
   *
   *  @param  name    Name of the student to enroll.
   *  @return      <code>true</code> if the student was added
   *        to the list, <code>false</code> otherwise.
   */
  public boolean enrollStudentConditionally(String name) {
    boolean isEnrolled = false;
    if (students.size() < capacity) {
    enrollStudent(name);
    isEnrolled = true;
    }
    return isEnrolled;
  }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?