For this assignment, you will implement two small classes that work together to implement the beginnings of an auction system. We will extend this program a couple of times throughout the semester as we learn more about Java and object-oriented programming.
Write your program in the style we first learned in Session 1:
Take small steps, and your tests will give you feedback as soon as possible. Use the GenerateTest program distributed with Session 1 to create your test class.
Consider the problem that faced Google last year. They wanted to sell a large number of shares of stock to new investors in the company. Many potential investors were willing to make a bid for shares. Each bid would consist of some number of shares at some offer price. Different bidders would offer different prices, and together they would request so many shares that Google would not be able to satisfy them all.
This is a general problem often solved with an auction.
For example, suppose that I have 100 books to sell. I might receive two bids, one for 70 books at $20 per book and the other for 50 books at $35 per book.
A seller like Google could auction off their shares to the highest bidder. This allocation strategy satisfies the bid making the highest offer.
If I use this strategy in my book example, then I will sell 50 books to the highest bidder, at $35 per book.
This strategy risks leaving some shares unsold. But if the highest bidder requests more shares than are available, she is awarded only the number of shares available.
Another approach continues to allocate shares in decreasing order of offer price, until all shares have been sold. But this could be unfair to the highest bidders, who would pay more for their shares than the last bidders. (That may be okay, if we decide that the assurance that you will receive shares is worth the "premium" paid per share.)
To address both of these issues (unsold shares and a fair price to all), the seller can auction off their shares using a Dutch auction allocation strategy. In this approach, the seller satisfies bid in decreasing order of offer price until all shares have been sold. All bidders are charged the price of the lowest successful bid.
If I use a Dutch auction allocation in my book example, then I will sell 50 books to the highest bidder and 50 books to the second bidder. The second bidder makes the lowest successful bid, offering $20 per book, so both bidders are charged $20.
Here is another example, based on one given at eBay:
A seller has 10 pens for auction. Let's say that five people bid $1.50 for one pen each, three people bid $1.25 for one pen each, one person bids $1.00 each for 5 pens, and fifty people bid $0.50 for one pen each.
- The $1.50 bidders bid higher than anyone else, so each is awarded a pen. That leaves 5 pens.
- The three $1.25 bidders bid higher than anyone left, so each is awarded a pen. That leaves 2 pens left.
- The $1.00 bid is the highest remaining, so he gets next dibs. He requested five pens, but only two remain, so he is awarded two pens.
- The other fifty bidders receive nothing.
The final price for all pens is $1.00, even though some folks placed a high bid of $1.50. All winning bidders pay the same price: the lowest successful bid.
This strategy ensures that all shares will be sold, at a price fair to all bidders..
A variation of Dutch auction allows the seller to set a minimum bid. Shares are allocated as described above, unless the offer price ever falls below the minimum, at which time the auction ends -- even if unsold share remain.
Notice that the seller makes a trade-off when choosing between these two strategies. Selling some of the shares at the highest bid price may result in more revenue than selling all of the shares at the last successful bid price.
In my book example, the Dutch auction approach brings in 100 * $20 = $2000. The highest-bidder approach brings in 50 * $35 = $1750. The difference is $2000 - $1750 = $250.
If the highest bidder had bid $42 per book, then the highest-bidder approach brings in 50 * $42 = $2100, and the difference is $100.
Even when a Dutch auction results in less revenue, it is generally viewed as a fairer way to distribute all shares.
Implement a simple auction program consisting of the following components.
A bid consists of a bidder ID (a String), the number of shares desired (an int), and the price being offered (a double). A bid should be able to tell a user:
In our auction program, you will use an array of bids to represent a collection of bids made for a lot of items being sold.
A highest-bidder allocation object receives the number of shares to be sold as an argument to its constructor. When asked to auction the shares, it receives an array of bids as an argument. It then returns the bid that is accepted, with the correct number of shares sold.
A Dutch auction allocation object receives the number of shares to be sold as an argument to its constructor. When asked to auction the shares, it receives an array of bids as an argument. It returns an array of bids that are accepted, with the correct number of shares and sale price.
Extra credit: Implement the variation in which the seller may set a minimum bid when it asks the object to auction off the shares.
An auction is told how how many shares are available to be sold when it is created. It responds to three messages:
In response to both auction requests, an auction returns the winning bid(s) as its response.
You may implement these requirements in any order you choose. But I suggest you start simple, say with Bid, and then add one strategy at a time.
By the due date and time, submit the files
Be sure that your submission follows all homework submission requirements.