Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import javax.swing.*;
- public class Lot
- {
- private final int number;
- private String description;
- private Bid highestBid;
- public Lot (int number, String description)
- {
- this.number = number;
- this.description = description;
- this.highestBid = null;
- }
- /**
- * Attempt to bid for this lot.
- * A succesful bid must have a value higher than any existing bid.
- * @param bid A new bid
- * @return true if succesful. false otherwise
- */
- public boolean bidFor(Bid bid)
- {
- if (highestBid==null)
- {
- highestBid=bid;
- return true;
- }
- else if (bid.getValue() > highestBid.getValue())
- {
- highestBid = bid;
- return true;
- }
- else
- {
- return false;
- }
- }
- /**
- * @return A string representation of this lot's details.
- */
- public String toString()
- {
- String details = number + ": " + description;
- if (highestBid != null)
- {
- details += " Bid: " + highestBid.getValue();
- }
- else
- {
- details += " (No bid))";
- }
- return details;
- }
- /**
- * @return The lot's number.
- */
- public int getNumber()
- {
- return number;
- }
- /**
- * @return The lot's description.
- */
- public String getDescription()
- {
- return description;
- }
- /**
- * @return The highest bid for this lot.
- * This could be null if there is no current bid.
- */
- public Bid getHighestBid()
- {
- return highestBid;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment