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

📄 patron.java

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

import dslib.list.LinkedListUos;
import dslib.exception.*;

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

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

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

	/**	Process the borrowing of book b.
		Analysis: Time = O(1) */
	public void borrowBook(LibraryBook b)
	{
		borrowedBooks.insert(b);
	}

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

		borrowedBooks.delete(b);
	}

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

⌨️ 快捷键说明

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