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

📄 bag.java

📁 Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套 代码
💻 JAVA
字号:
/** Bag Class * Author: David D. Riley * Date: June, 2004 * *  class invariant *      A Bag object ... *          * is a container of zero or more other objects *          * is capable of storing anything that conforms to Object  */public class Bag<ItemType> extends SimpleList<ItemType> {	/**	post:   this is an empty bag (i.e. size() == 0) */	public Bag()  {		super();	} 		/**	post:   result == number of items in this Bag	 *	note:   this method is inherited      *///	public int size()   	/** post:   this ==  this@pre with some z inserted     *          and  size() == size()@pre + 1     *  note:   this method is inherited     *///	public void add(ItemType z)   	/** pre:    count() > 0  <br>	 *	post:   this ==  this@pre with some item removed     *          and  size() == size()@pre - 1     *  note:   this method is inherited      *///	public void remove()   	/**	pre:    size() > 0     *  post:   result == one of the items from this Bag     */	public ItemType item()   {		int skipCount;		super.reset();		// the following code randomizes which item is returned.		skipCount = (int) (Math.random() * size());		for ( ; skipCount>0; skipCount--)   {			super.next();		}		return super.next();	}	public String toString()  {		String str = "";		super.reset();		while (super.hasNext())   {			str = str + " " + super.next().toString();		}		return str;	} // The methods below are overridden to disable them.	/**	post:   this method is disabled */	public void reset() {	} 	/**	post:   this method is disabled */	public ItemType next()  {        return null;	}  }

⌨️ 快捷键说明

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