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

📄 librarypatron.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
package patronBook;

import simple.*;

/**	A library patron with a name, list of books borrowed, and methods to
	borrow and return a book. */
public class LibraryPatron
{
	/**	Name of the patron. */
	public String name;

	/**	List of the books borrowed by the patron. */
	protected OrderedSimpleList borrowedBooks;

	/**	Initialize the patron and the list of books on loan.
		Analysis: Time = O(1) */
	public LibraryPatron(String n)
	{
		name = n;
		borrowedBooks = new OrderedSimpleList();
	}

	/**	Process the borrowing of book b.
		Analysis: Time = O(k), k = number of books borrowed */
	public void borrowBook(ComparableBook b)
	{
		borrowedBooks.insert(b);
	}

	/**	Process the returning of book b.
		Analysis: Time = O(k), k = number of books borrowed
		PRECONDITION:
			borrowedBooks.has(b) */
	public void returnBook(ComparableBook b) throws NoCurrentItemUosException
	{
		borrowedBooks.search(b);
		if (!borrowedBooks.itemExists())
			throw new NoCurrentItemUosException("Patron cannot return a book, "
					+ "if it isn't in the Patron's list of borrowed books");
	
		borrowedBooks.deleteItem();
	}

	/**	String representation of the patron.
		Analysis: Time = O(k), k = number of books borrowed */
	public String toString()
	{
		return "\n" + name + " has on loan\n" + borrowedBooks.toString() + "\n";
	}
}

⌨️ 快捷键说明

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