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

📄 labclass.java

📁 objects first with java: a practical introduction using bluej 英国爱丁堡大学java教程源代码
💻 JAVA
字号:
import java.util.*;/** * The LabClass class represents an enrolment list for one lab class. It stores * the time, room and participants of the lab, as well as the instructor's name. *  * @author Michael Kolling and David Barnes * @version 2001.05.24 */public class LabClass{    private String instructor;    private String room;    private String timeAndDay;    private List students;    private int capacity;        /**     * Create a LabClass with a maximum number of enrolments. All other details     * are set to default values.     */    public LabClass(int maxNumberOfStudents)    {        instructor = "unknown";        room = "unknown";        timeAndDay = "unknown";        students = new ArrayList();        capacity = maxNumberOfStudents;    }    /**     * Add a student to this LabClass.     */    public void enrolStudent(Student newStudent)    {        if(students.size() == capacity) {            System.out.println("The class is full, you cannot enrol.");        }        else {            students.add(newStudent);        }    }        /**     * Return the number of students currently enrolled in this LabClass.     */    public int numberOfStudents()    {        return students.size();    }        /**     * Set the room number for this LabClass.     */    public void setRoom(String roomNumber)    {        room = roomNumber;    }        /**     * Set the time for this LabClass. The parameter should define the day     * and the time of day, such as "Friday, 10am".     */    public void setTime(String timeAndDayString)    {        timeAndDay = timeAndDayString;    }        /**     * Set the name of the instructor for this LabClass.     */    public void setInstructor(String instructorName)    {        instructor = instructorName;    }        /**     * Print out a class list with other LabClass details to the standard     * terminal.     */    public void printList()    {        System.out.println("Lab class " + timeAndDay);        System.out.println("Instructor: " + instructor + "   room: " + room);        System.out.println("Class list:");        Iterator i = students.iterator();        while(i.hasNext()) {            Student student = (Student)i.next();            student.print();        }        System.out.println("Number of students: " + numberOfStudents());    }}

⌨️ 快捷键说明

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