填空题

    电视机遥控器就是一个迭代器的实例,通过它可以实现对电视机频道集合的遍历操作,现有TCL和创维两种品牌电视机,模拟电视机遥控器的实现。补全以下实现代码。//抽象聚合类public interface Television{TVIterator createIterator();}//具体聚合类public class TCLTelevision implements Television{publicObject[] obj={"频道1","频道2","频道3","频道4","频道5"};public TVIterator createIterator(){//创建对应的TCL遥控器对象return _____(1)______;}}//抽象迭代器类public interface TVIterator{void setChannel(int i);void next();void previous();boolean isLast();Object currentChannel();boolean isFirst();}//具体迭代器类class TCLIterator implements TVIterator{private int currentIndex=0;private TCLTelevision tcl;public TCLIterator(TCLTelevision tcl) {//构造注入_____(2)______;}public void next(){//访问下一个频道if(currentIndex<_____(3)______){currentIndex++;}}public void previous(){//访问上一个频道if(currentIndex>0){currentIndex--;}} public void setChannel(int i){//设置频道currentIndex=i;}public Object currentChannel(){//获取当前频道return tcl.obj[currentIndex];}public boolean isLast(){//判断是否为最后一个频道return currentIndex==tcl.obj.length;} public boolean isFirst(){//判断是否为第一个频道return currentIndex==0;}}//客户端public class Client{public static void display(Television tv){TVIterator i=tv.createIterator();System.out.println("电视机频道:");while(_____(4)______){//不是最后一个频道,则进入循环遍历System.out.println(i.currentChannel().toString());_____(5)______;}}public static void main(String a[]){Television tv;tv=new TCLTelevision();display(tv);//调用显示方法遍历}}


    火星搜题