Homework Assignment 3

A Simple Auction Program

CS 2530
Intermediate Computing

Due: Friday, September 21, at 5:00 PM


Note the unusual due date and time.

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.

This is your first multi-class program, and your first assignment that is essentially "from scratch". I encourage you to take small steps and test your code as soon as possible.

Be sure to follow the course coding standards in addition to the usual homework submission requirements.

Here are some Java-specific items that might help you with the assignment:

Background: Auctions and Allocations

An auction is a process for selling goods in which the seller offers the good for sale, prospective buyers make bids to buy the goods at a particular price, and the seller selects a buyer, usually on the basis of the highest bid. There are a number of variations possible in all three phases of the process, though the allocation strategy -- the selection of buyer(s) and price -- offers the most interesting variations in practice.

The simplest allocation strategy is to award the goods to the highest bidder. This allocation strategy satisfies the bid making the highest offer. This strategy risks leaving some items unsold, if the highest bidder requests fewer items than are offered.

For example, suppose that I have 100 books to sell and that I receive two bids: one for 70 books at $20 per book, and one for 50 books at $35 per book. Using the highest-bidder strategy, I will sell 50 books to the highest bidder, at $35 per book.

Other allocation strategies aim to eliminate the risk of unsold items and to increase the level of fairness for bidders.


Implement a simple auction program consisting of the following components.

  1. Write a class for representing a Bid.

    A bid consists of a bidder ID (a String), the number of shares desired (an int), and the price being offered (also an int, in cents). It receives all three at the time it is created.

    A bid should be able to respond to these messages:

    In your auction program, you will use an array of bids to represent all the bids made for a particular lot of items being sold.

  2. Write a class that represents an Auction.

    When an auction is created, it is given how how many items are available for sale and an array of bids. It responds to two messages:

    In response to the execute request, the auction returns a Bid with the correct number of shares sold.

  3. Write a driver program that demonstrates your code.

    Your driver should create at least three auctions that test your code and demonstrate its correctness. The set of bids used for each can be small, in the 3-5 range; just be sure that each auction tests your code in a different way. (For example, what happens if the highest bidder request more items than are available?)

    Your driver should display the winning bid for each auction as well as its range of bid offers.


By the due date and time, submit these files:

Be sure that your submission follows all homework submission requirements.

Eugene Wallingford ..... wallingf@cs.uni.edu ..... September 16, 2012