⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 auction.java

📁 现在在国外大学里最流行的java学习软件,同时还有大量的example,在名为project的文件里.安装好后用bluej打开peoject的例子,可以进行你想要的任何变化.同时可以了解大量的源码
💻 JAVA
字号:
import java.util.ArrayList;/** * 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 */public class Auction{    // The list of Lots in this auction.    private ArrayList<Lot> lots;    // The number that will be given to the next lot entered    // into this auction.    private int nextLotNumber;    /**     * Create a new auction.     */    public Auction()    {        lots = new ArrayList<Lot>();        nextLotNumber = 1;    }    /**     * Enter a new lot into the auction.     * @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.     */    public void showLots()    {        for(Lot lot : lots) {            System.out.println(lot.toString());        }    }        /**     * Bid for a lot.     * A message indicating whether the bid is successful or not     * is printed.     * @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)    {        Lot selectedLot = getLot(lotNumber);        if(selectedLot != null) {            boolean successful = selectedLot.bidFor(new Bid(bidder, value));            if(successful) {                System.out.println("The bid for lot number " +                                   lotNumber + " was successful.");            }            else {                // Report which bid is higher.                Bid highestBid = selectedLot.getHighestBid();                System.out.println("Lot number: " + lotNumber +                                   " already has a bid of: " +                                   highestBid.getValue());            }        }    }    /**     * Return the lot with the given number. Return null     * if a lot with this number does not exist.     * @param lotNumber The number of the lot to return.     */    public Lot getLot(int lotNumber)    {        if((lotNumber >= 1) && (lotNumber < nextLotNumber)) {            // The number seems to be reasonable.            Lot selectedLot = lots.get(lotNumber - 1);            // Include a confidence check to be sure we have the            // right lot.            if(selectedLot.getNumber() != lotNumber) {                System.out.println("Internal error: Lot number " +                                   selectedLot.getNumber() +                                   " was returned instead of " +                                   lotNumber);            }            return selectedLot;        }        else {            System.out.println("Lot number: " + lotNumber +                               " does not exist.");            return null;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -