示例#1
0
 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;
 }
示例#2
0
 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;
 }
示例#3
0
 public void Lose()
 {
     if (!(state == BookConstants.BookState.ON_LOAN))
     {
         throw new ApplicationException(String.Format("Illegal operation in state : {0}", state));
     }
     state = BookConstants.BookState.LOST;
 }
示例#4
0
 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;
 }
示例#5
0
 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;
     }
 }
示例#6
0
 public void Repair()
 {
     if (!(state == BookConstants.BookState.DAMAGED))
     {
         throw new ApplicationException(String.Format("Illegal operation in state : {0}", state));
     }
     state = BookConstants.BookState.AVAILABLE;
 }