public Book(string author, string title, string callNumber, int bookID) { if (!sane(author, title, callNumber, bookID)) { throw new ArgumentException("Member: constructor : bad parameters"); } this.author = author; this.title = title; this.callNumber = callNumber; this.id = bookID; this.state = BookConstants.BookState.AVAILABLE; this.loan = null; }
public void Borrow(ILoan loan) { if (loan == null) { throw new ArgumentException("Book: borrow : Bad parameter: loan cannot be null"); } if (!(state == BookConstants.BookState.AVAILABLE)) { string mesg = String.Format("Illegal operation in state : {0}", state); throw new ApplicationException(mesg); } this.loan = loan; state = BookConstants.BookState.ON_LOAN; }
public void Lose() { if (!(state == BookConstants.BookState.ON_LOAN)) { throw new ApplicationException(String.Format("Illegal operation in state : {0}", state)); } state = BookConstants.BookState.LOST; }
public void Dispose() { if (!(state == BookConstants.BookState.AVAILABLE || state == BookConstants.BookState.DAMAGED || state == BookConstants.BookState.LOST)) { throw new ApplicationException(String.Format("Illegal operation in state : {0}", state)); } state = BookConstants.BookState.DISPOSED; }
public void ReturnBook(bool damaged) { if (!(state == BookConstants.BookState.ON_LOAN || state == BookConstants.BookState.LOST)) { throw new ApplicationException(String.Format("Illegal operation in state : {0}", state)); } loan = null; if (damaged) { state = BookConstants.BookState.DAMAGED; } else { state = BookConstants.BookState.AVAILABLE; } }
public void Repair() { if (!(state == BookConstants.BookState.DAMAGED)) { throw new ApplicationException(String.Format("Illegal operation in state : {0}", state)); } state = BookConstants.BookState.AVAILABLE; }