嘿,所有。我被要求創建一個使用迭代器來打印'lots'細節的方法。我可以創建一個迭代器來打印所有的細節,但是,對於沒有被購買的任何批次,一條消息應該打印出這個事實,我不確定如何添加該代碼。我正在關注的公共無效關閉方法。這是我迄今爲止所擁有的。非常感謝幫助。迭代器和打印細節
public class Auction{
// The list of Lots in this auction.
private final ArrayList<Lot> lots;
// The number that will be given to the next lot entered
// into this auction.
private int nextLotNumber;
/**
* Create a new auction.
*/
public Auction(){
lots = new ArrayList<Lot>();
nextLotNumber = 1;
}
/**
* Enter a new lot into the auction.
*
* @param description
* A description of the lot.
*/
public void enterLot(final String description){
lots.add(new Lot(nextLotNumber, description));
nextLotNumber++;
}
/**
* Show the full list of lots in this auction.
*/
public void showLots(){
for(final Lot lot : lots){
System.out.println(lot.toString());
}
}
public void close(){
final Iterator<Lot> it = lots.iterator();
while(it.hasNext()){
}
}
/**
* Bid for a lot. A message indicating whether the bid is
* successful or not is printed.
*
* @param number
* The lot number being bid for.
* @param bidder
* The person bidding for the lot.
* @param value
* The value of the bid.
*/
public void bidFor(final int lotNumber,
final Person bidder,
final long value){
final Lot selectedLot = getLot(lotNumber);
if(selectedLot != null){
final boolean successful =
selectedLot.bidFor(new Bid(bidder, value));
if(successful){
System.out.println("The bid for lot number " + lotNumber
+ " was successful.");
} else{
// Report which bid is higher.
final Bid highestBid = selectedLot.getHighestBid();
System.out.println("Lot number: " + lotNumber
+ " already has a bid of: " + highestBid.getValue());
}
}
}
}
這是一個功課題嗎? – Wyzard 2010-11-30 12:37:56
你能提供更多關於完整`Lot` API的細節嗎? – 2010-11-30 12:38:26