【发布时间】:2014-03-12 06:33:40
【问题描述】:
我有两个班级,Club 和 party。 Clubextends通用Queue<E>并实现fitnessInterface。
Queue<E> implements QueueInterface<E>
俱乐部
public class Club extends Queue<Bachelor> implements fitnessInterface{
protected Queue<Bachelor> bachelorQ;
public Club(){
super();
bachelorQ = new Queue<Bachelor>();
}
public boolean Eligible(Bachelor bachelor){
if(bachelor==null){throw new NullPointerException();}
return true;
}
@Override
public QueueInterface<Bachelor> enqueue(Bachelor bachelor){
if(bachelor==null){
throw new NullPointerException();
else{
bachelorQ.enqueue(bachelor); }
return this; //the class queue
}
}
聚会
public class Party extends Club{
super();
}
@Override
public boolean Eligible(Bachelor bachelor){
if(bachelor==null){throw new NullPointerException();}
if(bachelor.getPushups()>=25){return true;}
return false;
}
}
Bachelor 类扩展了 QueueInterface,并具有一个构造函数,该构造函数接受 Integer 作为参数,并具有 getPushUps() 方法等。
问题是当我创建一个Party 对象并尝试将单身汉拉尔夫或查理排入队列时,它仍然是空的。
我的通用 Queue 类完美运行。它有dequeue、enqueue、isEmpty、peek、size 和toString 方法。一切正常。
主要
public static void main(String[] args){
Party bigParty = new Party();
Bachelor jack,charlie,ralph;
jack = new Bachelor(15);
ralph = new Bachelor(27);
charlie = new Bachelor(39);
//Eligibility tests
System.out.println(bigParty.Eligible(charlie));
System.out.println(bigParty.Eligible(ralph));
System.out.println(bigParty.Eligible(jack));
System.out.println(bigParty.enqueue(ralph));
System.out.println(bigParty.enqueue(charlie));
System.out.println(bigParty.size());
System.out.println(bigParty.bachelorQ.size());
}
输出
true
true
false
[]
[]
0
2
【问题讨论】:
标签: java generics inheritance linked-list queue