⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 roster.java

📁 < ProJavaProgrammingSecondEdition> 书中例程源码
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -