kidclub.java

来自「正在学习Java的人或许能从中得到自己想要的东西」· Java 代码 · 共 39 行

JAVA
39
字号
import java.util.*;

public class kidClub
implements Enumeration {
    private String clubMask;     //name of club
    private Kid kid;             //next kid to return
    private Enumeration ke;      //gets all kids
    private KidData kdata;       //class containing kids
//----------------------------------------
    public kidClub(KidData kd, String club) {
        clubMask = club;     //save the club
        kdata = kd;          //copy the class
        kid = null;          //default
        ke = kdata.elements();  //get Enumerator
    }
//----------------------------------------
    public boolean hasMoreElements() {
        //return true if there are any more kids 
        //belonging to the specified club
        boolean found = false;
        while (ke.hasMoreElements() && ! found) {
            kid = (Kid)ke.nextElement();
            found = kid.getClub().equals(clubMask);
        }
        if (! found)
            kid = null;    //set to null if none left
        return found;
    }
//----------------------------------------
    public Object nextElement() {
        if (kid != null)
            return kid;
        else
            //throw exception if access past end
            throw new NoSuchElementException();
    }
}

⌨️ 快捷键说明

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