Question

In: Computer Science

Part 2 BeerBatch Class /** * A class to model an item (or set of items)...

Part 2

BeerBatch Class

/**
* A class to model an item (or set of items) in an
* auction: a batch.
*/
public class BeerBatch
{
    // A unique identifying number.
    private final int number;
    // A description of the batch.
    private String description;
    // The current highest offer for this batch.
    private Offer highestOffer;

    /**
     * Construct a BeerBatch, setting its number and description.
     * @param number The batch number.
     * @param description A description of this batch.
     */
    public BeerBatch(int number, String description)
    {
        this.number = number;
        this.description = description;
        this.highestOffer = null;
    }

    /**
     * Attempt an offer for this batch. A successful offer
     * must have a value higher than any existing offer.
     * @param offer A new offer.
     * @return true if successful, false otherwise
     */
    public boolean bidFor(Offer offer)
    {
        if(highestOffer == null) {
            // There is no previous bid.
            highestOffer = offer;
            return true;
        }
        else if(offer.getAmount() > highestOffer.getAmount()) {
            // The bid is better than the previous one.
            highestOffer = offer;
            return true;
        }
        else {
            // The bid is not better.
            return false;
        }
    }
  
    /**
     * @return A string representation of this batch's details.
     */
    public String batchDetail()
    {
        return "TO DO";
    }

    /**
     * @return The batch's number.
     */
    public int getNumber()
    {
        return number;
    }

    /**
     * @return The batch's description.
     */
    public String getDescription()
    {
        return description;
    }

    /**
     * @return The highest offer for this lot.
     *         This could be null if there is
     *         no current bid.
     */
    public Offer getHighestOffer()
    {
        return highestOffer;
    }
}
Offer Class

/**
* A class that models an offer.
* It contains a reference to the Person bidding and the amount of the offer.
*/
public class Offer
{
    // The person making the bid.
    private final Bidder bidder;
    // The amount of the offer.
    private final int amount;

    /**
     * Create an offer.
     * @param bidder Who is bidding for the batch.
     * @param x The amount of the offer.
     */
    public Offer(int x, Bidder b)
    {
        this.bidder = b;
        this.amount = x;
    }

    /**
     * @return The bidder.
     */
    public Bidder getBidder()
    {
        return bidder;
    }

    /**
     * @return The amount of the offer.
     */
    public int getAmount()
    {
        return amount;
    }
}

Solutions

Expert Solution

/**
* A class to model an item (or set of items) in an
* auction: a batch.
*/
public class BeerBatch
{
    // A unique identifying number.
    private final int number;
    // A description of the batch.
    private String description;
    // The current highest offer for this batch.
    private Offer highestOffer;

    /**
     * Construct a BeerBatch, setting its number and description.
     * @param number The batch number.
     * @param description A description of this batch.
     */
    public BeerBatch(int number, String description)
    {
        this.number = number;
        this.description = description;
        this.highestOffer = null;
    }

    /**
     * Attempt an offer for this batch. A successful offer
     * must have a value higher than any existing offer.
     * @param offer A new offer.
     * @return true if successful, false otherwise
     */
    public boolean bidFor(Offer offer)
    {
        if(highestOffer == null) {
            // There is no previous bid.
            highestOffer = offer;
            return true;
        }
        else if(offer.getAmount() > highestOffer.getAmount()) {
            // The bid is better than the previous one.
            highestOffer = offer;
            return true;
        }
        else {
            // The bid is not better.
            return false;
        }
    }
  
    /**
     * @return A string representation of this batch's details.
     */
    public String batchDetail()
    {
       return "BeerBatch [number=" + number + ", description=" + description + ", highestOffer=" + highestOffer + "]";
    }
    

        /**
     * @return The batch's number.
     */
    public int getNumber()
    {
        return number;
    }

    /**
     * @return The batch's description.
     */
    public String getDescription()
    {
        return description;
    }

    /**
     * @return The highest offer for this lot.
     *         This could be null if there is
     *         no current bid.
     */
    public Offer getHighestOffer()
    {
        return highestOffer;
    }
}

/**
* A class that models an offer.
* It contains a reference to the Person bidding and the amount of the offer.
*/
class Offer
{
    // The person making the bid.
    private final Bidder bidder;
    // The amount of the offer.
    private final int amount;

    /**
     * Create an offer.
     * @param bidder Who is bidding for the batch.
     * @param x The amount of the offer.
     */
    public Offer(int x, Bidder b)
    {
        this.bidder = b;
        this.amount = x;
    }

    /**
     * @return The bidder.
     */
    public Bidder getBidder()
    {
        return bidder;
    }

    /**
     * @return The amount of the offer.
     */
    public int getAmount()
    {
        return amount;
    }
}

Related Solutions

source: /** * A class to model an item (or set of items) in an *...
source: /** * A class to model an item (or set of items) in an * auction: a batch. */ public class BeerBatch { // A unique identifying number. private final int number; // A description of the batch. private String description; // The current highest offer for this batch. private Offer highestOffer; /** * Construct a BeerBatch, setting its number and description. * @param number The batch number. * @param description A description of this batch. */ public BeerBatch(int...
The data provided below is the same for each item in a set of interrelated items...
The data provided below is the same for each item in a set of interrelated items about the FIFO approach to processes costing. Only the question asked tends to differ from item to item. Together this set of items addresses the same problem. Students are encouraged to work the ENTIRE problem out on scratch paper before responding to any items that relate to this problem. Knuckle makes t-shirts. It uses the FIFO approach to process costing and has a single-stage...
, we are given a set of n items. Each item weights between 0 and 1....
, we are given a set of n items. Each item weights between 0 and 1. We also have a set of bins (knapsacks). Each bin has a capacity of 1, i.e., total weight in any bin should be less than 1. The problem is to pack the items into as few bins as possible. For example Given items: 0.2, 0.5, 0.4, 0.7, 0.1, 0.3, 0.8 Opt Solution: Bin1[0.2, 0.8], Bin2[0.5, 0.4, 0.1], Bin3[0.7, 0.3] Each item must be placed...
Amazon was the company Items for Analysis: Criteria for Requirement 1, Part 1 Submission (Choose item...
Amazon was the company Items for Analysis: Criteria for Requirement 1, Part 1 Submission (Choose item A or B). A. Review your company’s current and long-term liabilities section of the most recently published balance sheet. Explain the details of the current and long-term debt based on the disclosures found in the financial statements. Do not complete a ratio analysis. Instead, focus on the details in the notes and determine how well the company presented the information to an informed reader....
Class GroceryBag collects instances of class Item in an appropriate data structure.                       Class Item      &n
Class GroceryBag collects instances of class Item in an appropriate data structure.                       Class Item                 ---------------------------                -String description                -int cost   //price in cents                ----------------------------                + [constructor, getters, and a toString() method] •         (Assume class Item has already been coded)                       Class GroceryBag (Highlights)                ----------------------------------                  -bag   // an ArrayList of <Item>                ----------------------------------                   assume public methods: constructor, totalBag(), findItem(String it), listAll(), etc. •         The ONLY thing you need to do in the space below is to...
Describe a model of prokaryotic gene regulation that was discussed in class, or a part of...
Describe a model of prokaryotic gene regulation that was discussed in class, or a part of your readings for this semester. How are genes in this “model” turned on, turned off, or how the rate of transcription can be slowed down.
Please add comments to this code! Item Class: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! Item Class: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
2. A Multi-Item (Summated Scale) Consist of a number of closely related items (questions or statements)...
2. A Multi-Item (Summated Scale) Consist of a number of closely related items (questions or statements) whose responses are combined into a composite score to measure a construct. Explain the benefits of measuring a construct with a multi-item scale as opposed to a single item scale in the context of an interview or questionnaire 3. Explain what is wrong with the following interview question and propose a solution to the problem you identify (i.e., re-write the question). (4 points) a....
public class Node<T> { Public T Item { get; set; } Public Node<T> Next; { get;...
public class Node<T> { Public T Item { get; set; } Public Node<T> Next; { get; set; } public Node (T item, Node<T> next) { … } } public class Polynomial { // A reference to the first node of a singly linked list private Node<Term> front; // Creates the polynomial 0 public Polynomial ( ) { } // Inserts term t into the current polynomial in its proper order // If a term with the same exponent already exists...
Under the job search model discussed in class, how will a company bankruptcy, like in part...
Under the job search model discussed in class, how will a company bankruptcy, like in part a, affect your labour force participation and wage a year later, if at all? Why
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT