📄 librarybook.java
字号:
package library;
import dslib.base.CursorUos;
/** A Book with additional instance variables onLoanTo, dueDate, and isOverdue.
It has methods to handle the borrowing and returning events. It also has a
position variable to record its position in an onLoan or overdue list. */
public class LibraryBook extends Book implements Comparable
{
/** Constructor for the class.
Analysis : Time = O(1) */
public LibraryBook(String newTitle, String newAuthor, String newIsbn)
{
super(newTitle, newAuthor, newIsbn);
}
/** Is current book less than `other'?.
Analysis: Time = O(1) */
public int compareTo(Object other)
{
return isbn.compareTo(((LibraryBook)other).isbn);
}
/** The patron who borrowed the book. */
protected Patron onLoanTo;
/** Is the book on loan?
Analysis: Time = O(1) */
public boolean isOnLoan()
{
return onLoanTo != null;
}
/** An integer to represent the date when the book is due. */
protected int dueDate;
/** Is the book already overdue? */
public boolean isOverdue;
/** Process the borrowing of the book by patron `p' on date `d'.
Analysis: Time = O(1) */
public void borrowed(Patron p, int d)
{
onLoanTo = p;
dueDate = d;
isOverdue = false;
}
/** String representation of the book information suitable for printing.
Analysis: Time = O(1) */
public String toString()
{
String result = super.toString();
if (isOnLoan())
{
result += " On loan to " + onLoanTo.name + " Due back " + dueDate;
if (isOverdue)
result += " already overdue.";
}
return result;
}
/** Process the returning of the book.
Analysis: Time = O(1) */
public void returned()
{
onLoanTo = null;
dueDate = 0;
isOverdue = false;
position = null;
}
/** Position of the book in either an onLoan list or the overdue list. */
protected CursorUos position;
/** Set the position to be x.
Analysis: Time = O(1) */
public void setPosition(CursorUos x)
{
position = x;
}
/** Record the fact that the book is overdue.
Analysis: Time = O(1) */
public void setOverdue()
{
isOverdue = true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -