Class Item

java.lang.Object
  |
  +--Item

public class Item
extends Object

An Item has a description and a minimal selling price. Bids can be placed on an item according to the auction rules.

Author:
Suzanne Menzel

Constructor Summary
Item(String description, int askingPrice)
          Constructs an Item from the given description and initial asking price.
 
Method Summary
 void close()
          Closes the bidding on this item.
 int getAskingPrice()
          Returns the initial asking price of this item.
 String getDescription()
          Returns the description of this Item.
 Bid getHighBid()
          Returns either null, meaning no bid has yet been accepted on this item, or the current high Bid.
 String getHistory()
          Returns the history of accepted bids on this item, as a String.
 int getNumBids()
          Returns the total number of bids accepted on this item so far.
 boolean isClosed()
          Returns true if and only if the bidding on this item has been closed, and false otherwise.
 void placeBid(Bid b)
          The given Bid is considered for this item.
 String toString()
          Returns a textual representation of this item, as a String.
 boolean wasBidOn()
          Returns true if and only if this item has an acceptable bid on it, and false otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Item

public Item(String description,
            int askingPrice)
Constructs an Item from the given description and initial asking price.

Method Detail

getDescription

public String getDescription()
Returns the description of this Item.


placeBid

public void placeBid(Bid b)
The given Bid is considered for this item. If the auction on this item has closed or the ceiling price in b does not meet or exceed the asking price on this item, then an appropriate message is displayed and the bid is ignored. Otherwise, b is either accepted or rejected. It is accepted (i.e., it becomes the current high bid) if it is the first bid to be placed on this item (in which case, it is accepted at the item's asking price) or if its ceiling price exceeds the ceiling on the current high bid (in which case it is accepted for one dollar more than that value). If the bid b is rejected, then the current high bid must be raised accordingly to reflect the new offer.


getHighBid

public Bid getHighBid()
Returns either null, meaning no bid has yet been accepted on this item, or the current high Bid.


wasBidOn

public boolean wasBidOn()
Returns true if and only if this item has an acceptable bid on it, and false otherwise.


getAskingPrice

public int getAskingPrice()
Returns the initial asking price of this item.


getNumBids

public int getNumBids()
Returns the total number of bids accepted on this item so far.


getHistory

public String getHistory()
Returns the history of accepted bids on this item, as a String.


close

public void close()
Closes the bidding on this item.


isClosed

public boolean isClosed()
Returns true if and only if the bidding on this item has been closed, and false otherwise.


toString

public String toString()
Returns a textual representation of this item, as a String. For example:
     > wand
     Magic wand...$32 (hpotter)
     > hat
     Sorting hat...no bids yet...min bid is $78
     > broom
     Broomstick...closed
     

Overrides:
toString in class Object