Question

In: Computer Science

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 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; } } Question: Implement the method batchDetail() in the BeerBatch class. Below you see the details of the first three batches created in the BearAuction constructor. For your string use the same format as below! 1: 1892 Traditional Bid: 14 by Juliet (female, 27) 2: Iceberg Lager No bid 3: Rhinegold Altbier Bid: 17 by William (male, 22).

Solutions

Expert Solution

Auction.java

import java.util.ArrayList;
import java.util.Iterator;
public class Auction
{
    private ArrayList<Lot> lots;
    private int nextLotNumber;
    private Auction auction1;
    private Lot chindo;
    private Lot keyfi;
    private Lot taco;

    public Auction()
    {
        lots = new ArrayList<>();
        nextLotNumber = 1;
    }
    public void createScenario()
    {
        int n = 1;
        Person jack = new Person("John");
        Person jill = new Person("Bob");

        Lot abc = new Lot((n++), "Used Abc");
        Lot def = new Lot((n++), "Def");
        Lot ghijklm = new Lot((n++), "Ghi Jklm");

        auction1.enterLot("abc");
        auction1.enterLot("def");
        auction1.enterLot("ghijklm");

        auction1.makeABid(1, jack, 569);
        auction1.makeABid(3, jill, 4545);

        close();

    }

    public ArrayList<Lot> getUnsold()
    {
        ArrayList<Lot> unsold = new ArrayList<Lot>();
        for(Lot lot: lots){
            Bid bid = lot.getHighestBid();

            if(bid == null){
                unsold.add(lot);
            }
        }
        return unsold;
    }


   public void close()
    {
        ArrayList noBid = new ArrayList<Lot>();
        System.out.println("The results of the auction are as follows:");

        System.out.println("-----------------------------------------------------");
        for(Lot lot : lots){
            Bid bid = lot.getHighestBid();
            if(bid != null){
                System.out.println("Item Number: " + lot.getNumber());
                System.out.println("Item Description: " + lot.getDescription());
                System.out.println("We have a winner!");
                System.out.println("Bidder: " + bid.getBidder());
                System.out.println("-----------------------------------------------------");
            }
        }
        System.out.println("The following items received no bids:");
        System.out.println(getUnsold());
    }


  

    public void enterLot(String description)
    {
        lots.add(new Lot(nextLotNumber, description));
        nextLotNumber++;
    }

    public void showLots()
    {
        for(Lot lot : lots) {
            System.out.println(lot.toString());
        }
    }

    public void makeABid(int lotNumber, Person bidder, long value)
    {
        Lot selectedLot = getLot(lotNumber);
        if(selectedLot != null) {
            boolean successful = selectedLot.bidFor(new Bid(bidder,value));
            if(successful) {
                System.out.println("The bid for lot number " +
                        lotNumber + " was successful.");
            }
            else {
                Bid highestBid = selectedLot.getHighestBid();
                System.out.println("Lot number: " + lotNumber + " already has a bid of: " + highestBid.getValue());
            }
        }
    }

  
    public Lot removeLot(int lotToRemove)
    {
        int index = 0;
        int rmvLot = lotToRemove;
        boolean found = false;

        if(lotToRemove >= lots.size()){
            return null;
        }
        else{
            while(index <= lots.size() && index <= (lotToRemove - 1) && found == false){
                Lot lot = lots.get(index);

                if((lots.get(index) == lots.get(rmvLot -1))){
                    found = true;
                }
                else{
                    index += 1;
                }
            }
        }
        return lots.get(index);
    }



    public Lot getLot(int lotNumber)
    {
        if((lotNumber >= 1) && (lotNumber < nextLotNumber)) {
            return lots.get((lotNumber-1));
        }
        else {
            System.out.println("Lot number: " + lotNumber +
                    " does not exist.");
            return null;
        }
    }
}

----------------------------------------------------------------------------------------------------------------------------------------------------------

Lot.java

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;
    }


    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;
        }
    }


    public String toString()
    {
        String details = number + ": " + description;
        if(highestBid != null) {
            details += "    Bid: " +
                    highestBid.getValue();
        }
        else {
            details += "    (No bid)";
        }
        return details;
    }


    public int getNumber()
    {
        return number;
    }


    public String getDescription()
    {
        return description;
    }


    public Bid getHighestBid()
    {
        return highestBid;
    }
}

----------------------------------------------------------------------------------------------------------------------------------------------------------

Bid.java

public class Bid
{
    private final Person bidder;
    private final long value;

    public Bid(Person bidder, long value)
    {
        this.bidder = bidder;
        this.value = value;
    }

    public Person getBidder()
    {
        return bidder;
    }

    public long getValue()
    {
        return value;
    }
}

----------------------------------------------------------------------------------------------------------------------------------------------------------

Person.java

public class Person
{
    private final String name;

    public Person(String name)
    {
        this.name = name;
    }

    public String getName()
    {
        return name;
    }
}

----------------------------------------------------------------------------------------------------------------------------------------------------------

Note: I hope the above-provided solution is as per your question. If you find any error in the code then please do let me know through comments. I'll try to resolve your issues. And one request is to please upload the question and code giving space. Thank You!!

We try harder to provide you the best solutions, UpVote!!Please!! Have a Nice Day......


Related Solutions

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...
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...
Write a python source code for a Unit class corresponding to the UML model of a...
Write a python source code for a Unit class corresponding to the UML model of a Unit shown. The description method should return a string value corresponding to the attributes of a Movie. Unit -code: String -name: String -credit points: int + __init__ (self, code, name, credit_points) + description (): String
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...
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;   ...
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...
Blake Company purchased two identical inventory items. The item purchased first cost $24.00, and the item...
Blake Company purchased two identical inventory items. The item purchased first cost $24.00, and the item purchased second cost $25.00. Blake sold one of the items for $44.00. Which of the following statements is true? Ending inventory will be lower if Blake uses the weighted-average rather than the FIFO inventory cost flow method. Cost of goods sold will be higher if Blake uses the FIFO rather than the weighted-average inventory cost flow method. The dollar amount assigned to ending inventory...
Which of the following 4 items is most likely to be classified as an A item...
Which of the following 4 items is most likely to be classified as an A item in ABC Analysis? annual usage unit cost widget 300 75 thingamajig 150 5 whatchamacallit 400 4 dohickey 82 60 A. whatchamacallit B. thingamajig C. dohickey D. widget
Question: For each of the following items, determine whether the item would be:
Question: For each of the following items, determine whether the item would be:a. added to the bank balanceb. subtracted from the bank balancec. added to the book balanced. subtracted from the book balance11. Interest revenue earned12. NSF check13. Deposit in transit14. Service charge15. Outstanding check 
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT