Write some classes to simulate online auctions

Assignment Help JAVA Programming
Reference no: EM131434722

Assignment: Data Structures in Java Lab

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):
o 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)
o 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

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

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:

Here is an explanation of the bidding:

1. 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. Sofia's bid is added to the stack and she becomes the winning bidder. We track the high bid and the maximum bid.)

2. New Bid: 12/5/2016, 12pm, 5 Jim. (Jim's 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.)

3. New Bid: 12/5/2016, 5pm, 10 Ashok. (Ashok's bid is higher than the reserve price and higher than the current high bid. Ashok's 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. Ashok's bid is added to the top of the stack.)

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

5. New Bid: 12/7/2016, 3pm, 15 Joey. (Joey's bid is higher than the reserve and higher than the current high bid. Joey's 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. Joey's bid is added to the top of the stack.)

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

7. 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:

1. Create the MCCBay object.
2. Read the time and record type (auction or bid) from the input file.
3. Check if any auctions have ended by this time.
4. Process the bid or auction
5. Repeat this until all input has been read.
6. 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.

Attachment:- auction.txt

Reference no: EM131434722

Questions Cloud

Yield to maturity of a bond : Differentiate between the coupon yield, the current yield, and the yield to maturity of a bond. Why do we have three different measures of bond yields -- what are the pros and cons of each?
Briefly discuss designing job-based pay system : Briefly discuss designing job-based pay system (i.e. merit pay, sales incentive pay) and person-focused programs. What considerations arise when making a transition from using a jobbased pay system to using pay-for-knowledge.
Additional benchmark data analytics project : This project is an additional benchmark data analytics project. The objective of this part of the project will be to do a comparative financial analysis of your company with the averages of the sample of four companies that will form your comparat..
Discuss any sociological aspects that may be causing wealth : Use the Internet to research the population of your community or town. City-Data, is a great Website to get you started. Identify whether you town is growing or declining. Describe at least one (1) sociological aspect that can be attributed to th..
Write some classes to simulate online auctions : CSC236- In this lab, you will you will write some classes to simulate online auctions. Each item has a reserve price, which is the minimum sale price set by the seller.
Which the inference-observation confusion occurred : Describe an incident , possibly involving yourself, in which the inference-observation confusion occurred. analyze specifically why it occurred, what might have been done to prevent its occurrence, and what measures would prevent its recurrence.
Fudging the accounts receivable documents : Chronic tardiness and absenteeism because the employee is taking care of an aging parent. Sexual harassment accused by a woman against another woman. "Fudging" the accounts receivable documents or inventory control documents. Make a list of steps to ..
Constant dividend pay-out ratio : Next year, the company will declare an ordinary dividend of 34 cents per share for the 2017 financial year and the company is expected to maintain a constant dividend pay-out ratio of 70% of after tax earnings in the future.
Describe the mentality of londoners at the end of the 1800s : In what ways did London become a world city between 1700 and 1900 and how did new technologies shape London's cultural and commercial life in the 1700s and 1800s?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Java program to ask user to enter favorite color

Write a Java program to ask the user to enter favorite color, a favorite food, favorite animal, and first name of a friend or relative.

  Collaboration and social media

While planning for a new project, a young developer mentions that she used Facebook as a collaborative group space for developing her senior project. She tells you that it was the ideal solution since it was free and all of her group members were ..

  The new class has the attributes of: name - type string age

Here is my current assignment I got the cat file to work I'm just having trouble with the driver file. You must create two Java files called LastNameFirstNameUnit6Prog.java, and Cat.java. Ensure you include ALL files required to make your program com..

  You need to train for 10 weeks

You are preparing for a marathon. In order to prepare, you need to train for 10 weeks, running an increasing number of miles per week, starting at running at least 2 miles your first week up to 26 miles by week 10.

  Create an efficient object-oriented java application

Create an efficient Object-Oriented Java application that maintains information about college roommates who are renting a house together, for their realtor.

  Create an online student testing application

In this project you are required to create an online student testing application (called EzTest) with the following specifications: Students can use a web browser to register and log in to EzTest, Students can start a new lest from a list of availab..

  The data file being used contains records

The data file being used contains records with an employee's name, the number of hours they worked, and their hourly pay rate. Write a program to read the records of information and output (to the Output window or a dialog box) the employee's name..

  Java program to implement currency converter

Write a JAVA program that helps the user convert currency. The user will enter the amount in Kuwaiti dinars. The program will print the equivalent amount in US dollar and Euros count his change.

  What should a comment at the class level contain

How do you identify a comment so the Javadoc tool will recognize it and what should a comment at the class level contain?

  Write a program that allows a user to enter a line of text

write a program that allows a user to enter a line of text counts number of words and number of vowels in the sentence

  Create a program named schoolsdemo

Create a program named SchoolsDemo that allows a user to enter data about five school objects and then displays the school objects in order of enrollment size from smalles to largest.

  Write a restful web service demo example using spring mvc

Write a restful web service demo example using spring mvc

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd