Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.*; /** * A simple model of an auction. * The auction maintains a list of lots of arbitrary length. * * @author David

 image text in transcribed import java.util.*; /** * A simple model of an auction. * The auction maintains a list of lots of arbitrary length. * * @author David J. Barnes and Michael Kolling. * @version 2006.03.30 * * @author (of AuctionSkeleton) Lynn Marshall * @version 2.0 * * @author * @version * */ public class Auction { /** The list of Lots in this auction. */ private ArrayList lots; /** * The number that will be given to the next lot entered * into this auction. Every lot gets a new number, even if some lots have * been removed. (For example, if lot number 3 has been deleted, we don't * reuse it.) */ private int nextLotNumber; // You need to add something here. (Hint: an auction may be open or closed.) /** * Create a new auction. */ public Auction() { lots = new ArrayList(); nextLotNumber = 1; // you need to add something here -- see hint above. } /** * Add a second constructor here. This constructor takes * an Auction as a parameter. Provided the auction parameter * is closed, the constructor creates a new auction containing * the unsold lots of the closed auction. If the auction parameter * is still open or null, this constructor behaves like the * default constructor. * (You need to write the entire method.) */ /** * Enter a new lot into the auction. Returns false if the * auction is not open or if the description is null. * (You need to add the return type, update the documentation, * and change the code.) * * @param description A description of the lot. */ public void enterLot(String description) { lots.add(new Lot(nextLotNumber, description)); nextLotNumber++; } /** * Show the full list of lots in this auction. * * Print a blank line first, to make our output look nicer. * If there are no lots, print a message indicating this * (You need to update the code given below.) */ public void showLots() { for(Lot lot : lots) { System.out.println(lot.toString()); } } /** * Bid for a lot. * Do not assume that the lots are stored in numerical order. * Prints a message indicating whether the bid is successful or not. * * First print a blank line. * Then print whether or not the bid is successful. * If the bid is successful, also print the * lot number, high bidder's name, and the bid value. * If the bid is not successful, also print the lot number * and high bid (but not the high bidder's name). * * Returns false if the auction is closed, the lot doesn't * exist, the bidder is null, or the bid was not positive * and true otherwise (even if the bid was not high enough). * (You need to update the return type, documentation, and code.) * * @param number The lot number being bid for. * @param bidder The person bidding for the lot. * @param value The value of the bid. */ public void bidFor(int lotNumber, Person bidder, long value) { } /** * Return the lot with the given number. * Do not assume that the lots are stored in numerical order. * * Returns null if the lot does not exist. * (You need to update the code.) * * @param lotNumber The number of the lot to return. * * @return the Lot with the given number */ public Lot getLot(int lotNumber) { return null; } /** * Closes the auction and prints information on the lots. * First print a blank line. Then for each lot, * its number and description are printed. * If it did sell, the high bidder and bid value are also printed. * If it didn't sell, print that it didn't sell. * * Returns false if the auction is already closed, true otherwise. * (You need to update the return type, documentation, and code.) */ public void close() { } /** * Returns an ArrayList containing all the items that have no bids so far. * (or have not sold if the auction has ended). * @return an ArrayList of the Lots which currently have no bids */ public ArrayList getNoBids() { return null; // remove this line -- it's just to get the code to compile } /** * Remove the lot with the given lot number, as long as the lot has * no bids, and the auction is open. * You must use an Iterator object to search the list and, * if applicable, remove the item. * Do not assume that the lots are stored in numerical order. * * Returns true if successful, false otherwise (auction closed, * lot does not exist, or lot has a bid). * (You need to update the return type, documentation, and code.) * * @param number The number of the lot to be removed. */ public void removeLot(int number) { } }

//lot class below

/** * A class to model an item (or set of items) in an * auction: a lot. * * @author David J. Barnes and Michael Kolling. * @version 2008.03.30 */ public class Lot { // A unique identifying number. private final int number; // A description of the lot. private String description; // The current highest bid for this lot. private Bid highestBid;

/** * Construct a Lot, setting its number and description. * @param number The lot number. * @param description A description of this lot. */ public Lot(int number, String description) { this.number = number; this.description = description; }

/** * Attempt to bid for this lot. A successful bid * must have a value higher than any existing bid. * @param bid A new bid. * @return true if successful, false otherwise */ public boolean bidFor(Bid bid) { if((highestBid == null) || (bid.getValue() > highestBid.getValue())) { // This bid is the best so far. highestBid = bid; return true; } else { return false; } } /** * @return A string representation of this lot's details. */ public String toString() { String details = number + ": " + description; if(highestBid != null) { details += " Bid: " + highestBid.getValue(); } else { details += " (No bid)"; } return details; }

/** * @return The lot's number. */ public int getNumber() { return number; }

/** * @return The lot's description. */ public String getDescription() { return description; }

/** * @return The highest bid for this lot. * This could be null if there is * no current bid. */ public Bid getHighestBid() { return highestBid; } }

SYSC 2004 Object-Oriented Software Development Assignment #2 Download file auction.zip from the "BlueJ Projects from Textbook" folder chapter04 in cuLearn and extract all the files into a folder called "auction". Also download file "AuctionSkeleton.java", found right below this file in the "Assignments" tab in cuLearn This assignment is loosely based on exercises 4.48 to 4.52 in Chapter 4 of the text book. Note, however, that there is more to the assignment than in the exercises. The "AuctionSkeleton.java" file contains comments as to exactly what you need to do. Some of the code from the original "Auction.java" class has been removed from "AuctionSkeleton.java" as you need to rewrite it. However, looking at the original code in "Auction.java" will be useful Add "AuctionSkeleton.java" to your project. Then rename the original "Auction.java" file to "oldAuction.java", so that you can refer to it as needed. Now you can rename "AuctionSkeleton.java" to "Auction.java". Note that in Java the convention is to have the file name the same as the name of the class. I called your starting point "AuctionSkeleton.java" just so you wouldn't have two files with the same name The main changes you need to make are as follows An auction can be open or closed. Certain methods may be performed only when the auction is in an open state (e.g. add an item, bid on an item, etc.). When an auction is closed only methods that don't change any fields should be invoked While lots are given a number when they are created, and originally start out stored in the auction list in numeric order, this numeric order may not be preserved as lots can be removed. Thus there could be 4 lots in our auction, numbered 1, 4, 5, and 8 (i.e. it is not the case that the "i"th item in our list will necessarily be lot item "i+1" A new auction can be created from a closed auction, and it will start out containing all the lots that didn't sell in the closed auction. Those unsold lots will keep their original lot numbers. Note that you will not reuse any of the lot numbers for the items that did sell Submit file "Auction.java" from the auction project using the SYSC 2004 Assignment submit prograrn for Assignment #2. Late submissions will not be accepted by the submit program or the instructor

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

Students also viewed these Databases questions