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

📄 city.java

📁 现在在国外大学里最流行的java学习软件,同时还有大量的example,在名为project的文件里.安装好后用bluej打开peoject的例子,可以进行你想要的任何变化.同时可以了解大量的源码
💻 JAVA
字号:
import java.util.Iterator;import java.util.LinkedList;import java.util.List;    /** * A collection of items in the city. *  * @author David J. Barnes and Michael Kolling * @version 2006.03.30 */public class City{    private List<Object> items;    private int width;    private int height;        private static final int DEFAULT_WIDTH = 35;    private static final int DEFAULT_HEIGHT = 35;    /**     * Constructor for objects of class City     * @param width The city's width.     * @param height The city's height.     */    public City(int width, int height)    {        if(width < 1) {            throw new IllegalArgumentException(                        "Width must be positive: " +                        width);        }        if(height < 1) {            throw new IllegalArgumentException(                        "Height must be positive: " +                        height);        }        this.width = width;        this.height = height;        items = new LinkedList<Object>();    }        /**     * Create a city of default size.     */    public City()    {        this(DEFAULT_WIDTH, DEFAULT_HEIGHT);    }        /**     * @return An iterator over the items.     */    public Iterator getItems()    {        return items.iterator();    }    /**     * Add the given item to the city's collection.     * @param item The item to be added.     */    public void addItem(Object item)    {        if(items.contains(item)) {            throw new IllegalArgumentException(                item + " already recorded in the city.");        }        items.add(item);    }    /**     * Remove the given item from the city's collection.     * @param item The item to be removed.     */    public void removeItem(Object item)    {        if(!items.remove(item)) {            throw new IllegalArgumentException(                        item + " is not in the city.");        }    }            /**     * @return A string representation of the city.     */    public String toString()    {        return "City size " + width + " by " + height;    }        /**     * @return The width.     */    public int getWidth()    {        return width;    }        /**     * @return The height.     */    public int getHeight()    {        return height;    }}

⌨️ 快捷键说明

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