Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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

Java, Programming

  • Category:- Java
  • Reference No.:- M92243492
  • Price:- $75

Priced at Now at $75, Verified Solution

Have any Question?


Related Questions in Java

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As