Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this lab you will you will write some classes to simulate online auctions. How Bidding Works The rules for bidding are as follows: each

In this lab you will you will write some classes to simulate online auctions.

How Bidding Works

The rules for bidding are as follows:

each item has a reserve price, which is the minimum sale price set by the seller

a bid is discarded if it is less than the reserve price

a bidder specifies the maximum they are willing to bid, called the maximum bid

the current bid is the winning bid at a given time during the auction

the current bid is only as high as needed to exceed the previous current bid; it may be less than the maximum specified by the bidder

a bid is discarded if its maximum is less than the current bid

if a new maximum bid is placed that is higher than the current bid (suppose A is the currently winning bidder, and B is the new bidder):

if the maximum for A is higher than the maximum for B, A is still winning the auction; the new current bid is 1 + (maximum of B)

if the maximum for B is higher than the maximum for A, then B is the new winner of the auction; the new current bid is 1 + (maximum of A)

Bidding Example

Given an auction for "Sample Auction Item", with auction number 256. The auction begins on 12/5/2016 at 7am and ends on 12/8/2016 at 11:59pm with a reserve price of $3. Here is a record of the bidding:

Bid Num Date Time Bid Result Winning Bidder Current High Bid Max Bid
1 12/5/2016 9:00 am Sofia 7 new high bidder Sofia 3 7
2 12/5/2016 12:00 pm Jim 5 current high bid increased Sofia 6 7
3 12/5/2016 5:00 pm Ashok 10 new high bidder Ashok 8 10
4 12/6/2016 10:00 am LiPing 8 no change Ashok 8 10
5 12/7/2016 3:00 pm Joey 15 new high bidder Joey 11 15

Here is an explanation of the bidding:

New Bid: 12/5/2016, 9am, 7 Sofia. (The stack is empty and Sofia's bid is above the reserve price; the high bid at this time needs to match the reserve price. Sofias bid is added to the stack and she becomes the winning bidder. We track the high bid and the maximum bid.)

New Bid: 12/5/2016, 12pm, 5 Jim. (Jims bid is greater than the reserve price and greater than the current high bid but it is not greater than the current max bid, so Sofia is still winning but her current high bid goes up. Therefore, Jim's bid is discarded and Sofia's bid is updated to be 1+ Jim's bid. A new bid object is created for Sofia with the new current high bid and is added to the top of the stack.)

New Bid: 12/5/2016, 5pm, 10 Ashok. (Ashoks bid is higher than the reserve price and higher than the current high bid. Ashoks bid is also higher than the current max bid, so Ashok is the new winning bidder and the current high bid becomes 1 + max of the current max bid. Ashoks bid is added to the top of the stack.)

New Bid: 12/6/2016, 10am, 8 LiPing. (LiPings bid is higher than the reserve price but not higher than the current high bid so LiPings bid is discarded. Stack is unchanged.)

New Bid: 12/7/2016, 3pm, 15 Joey. (Joeys bid is higher than the reserve and higher than the current high bid. Joeys bid is also higher than the current max bid, so Joey is the new winning bidder and the current high bid becomes 1 + max of the current max bid. Joeys bid is added to the top of the stack.)

Auction ends at 12/8/2016, 11:59pm.

The bid at the top of the stack is the winning bid. If we were to top() and pop() from the stack until it was empty, and print each bid, the bid history for this auction would be:

Auction Ended: Sample Auction Item, number 256 Winner: Joey Winning Bid: 11 Bid History: 12/7/2016, 3:00 pm, Joey, 11 12/6/2016, 5:00 pm, Ashok, 8 12/5/2016, 12:00 pm, Sofia, 6 12/5/2016, 9:00 am, Sofia, 1 

Input

There are two types of entries in the input file. Each entry is on a separate line. One type is to start an auction, the other is to bid on an auction.

The entry for an auction has the following fields, separated by blanks:

start time of auction

the word "auction"

auction id number

reserve bid

end time of auction

description of item on sale

The entry for a bid has the following fields, separated by blanks:

time bid is placed

the word "bid"

id number of auction on which bid is placed

maximum for this bid

name of bidder

The entries in the input are ordered by time: start time of auction and time of bid. The entries go from earliest to most recent. See below for more info on how to handle times.

Bid

Create a class to hold an individual bid. The Bid class needs fields for the bid info, plus a field for the current bid. Remember that the bid the user places is the maximum. The current bid may be less; instead of going right to the maximum, the current bid is just high enough to beat the competition. Suppose A is the winning bid and B is a new bid. If the maximum bid of B is above the current bid for A but less than the maximum for A then current for A will be raised to (1 + maximum of B), and A will still be winning. If the maximum of B is higher than the maximum of A, then B becomes the winner, and the current bid for B is (1 + maximum of A).

If the current bid for a winning bid is updated, a new Bid object is created for that bid, which contains the new current bid. Thus a single bid placed by a user can end up bidding multiple times to beat other bids that come in with lower maximums.

The Bid class will need the following methods:

constructor to initialize all fields

toString

update: Create a new instance of this bid with a higher current bid and new time. The higher current bid and the new time are the parms; return a new Bid object with the new current bid and time; all other fields remain the same.

some other simple methods: you don't need any sets, and you should create gets only when necessary; the update method will reduce the need for gets and sets

Auction

Create a class for an individual auction. The Auction class needs fields for the auction info, plus a stack to hold the bids. Use the ArrayBoundedStack class which you can find in shared files on campus cruiser. The stack will hold Bid objects. You will need the following methods:

constructor to initialize all fields

newBid: The parms are the info about the new bid: the bidder, the bid time, and the max bid. First the method determines whether the auction has ended. If not, the bidding rules are used to determine whether the new bid is the new winning bid. Let's call the current winning bid A and the new bid B. If B wins over A, calculate the current bid for B and push B onto the stack. If B doesn't win over A, calculate the current bid for A. If there is a new current bid for A, create a new bid object for A with this current bid and push it on the stack. HINT: look at the bid class methods.

over: If the auction is not active, return; this auction has alread ended. Otherwise print out the name and id of the auction. If there were no bids print a message saying there were no bids, otherwise print the auction number, winner, winning bid and all the bids on the auction's stack. Make the auction inactive.

equals: The equals method compares the auction number.

You will need some gets. Try to minimize your use of gets. You should not need any sets.

All Auctions

We need a class for all auctions, let's call it MCCBay. We need a container for all of the auctions, so this class will have an ArrayList as a field; the ArrayList will hold Auction objects. This class needs the following methods:

create auction: This method has parms for the Scanner and time; read the rest of the fields for the auction, create the Auction object and add it to the list.

process bid: The parms are the Scanner and the time. Read the rest of the fields and create the Bid object. Find the auction for this bid (using the auction number), then pass the bid to the newBid method for the auction, which will process the new bid. To search the ArrayList for the auction, create an auction object with the auction number. The contents of the other fields don't matter, because the equals method for the Auction will only compare the auction number. Use this "dummy" auction object to search the ArrayList for the auction that is being bid on.

end auctions: The parm is the current time; the method goes through all auctions and checks whether any active auction has ended. If it has, it calls the over method to print out the result of the auction.

end all: This method go through all auctions, If an auction is active, it calls the over method to print out the results of the auction.

Client Code

Your main method needs to do the following:

Create the MCCBay object.

Read the time and record type (auction or bid) from the input file.

Check if any auctions have ended by this time.

Process the bid or auction

Repeat this until all input has been read.

End any active auctions

Timestamps

For timestamps we will use the LocalDateTime class from the Java API. Look up this classes; you may find the documentation somewhat confusing; that's fine, but it's important to get used to looking up Java classes.

This class provide methods to create, print, and compare dates. Here is the information you need to work with these objects in your program.

To read and write these dates we need to describe the date format to read or print. To do so, we use a DateTimeFormatter object. (Look up this class too.) The DateTimeFormatter object can be created to use whatever date format you choose. We are going to use the format yyyy-mm-ddThh:mm:ss (date and time, separated by the character T)

Reading Date & Time

To read dates of the form (date and time, separated by the character T):

 2017:02:06T12:30:00 

We will read it as a String, then create a DateTimeFormatter, using the ISO_LOCAL_DATE_TIME format. Then we use the parse method of the LocalDateTime class to create the LocalDateTime object. Assume that strtime is a String containing the date and time, in the format shown above:

 LocalDateTime timestamp; DateTimeFormatter format = DateTimeFormatter.ISO_LOCAL_DATE_TIME; timestamp = LocalDateTime.parse(strtime, format); 

Printing Date & Time

To print a LocalDateTime object we will create a DateTimeFormatter with the SHORT formatstyle for both the date and the time. We will use the format() method of the LocalDateTime object to create a String representation of the LocalDateTime object timestamp:

 DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT,FormatStyle.SHORT); String strout = timestamp.format(formatter); 

This will print a LocalDateTime as

 2/18/15 5:24 PM 

Comparing Date & Time

Two LocalDateTime objects can be compared using the equals or compareTo methods of the LocalDateTime class. this programming would use Java lauguage

.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Datalog Engines In Databases

Authors: Bas Ketsman ,Paraschos Koutris

1st Edition

1638280428, 978-1638280422

More Books

Students also viewed these Databases questions

Question

What appears to be the readiness level of the employees?

Answered: 1 week ago