//=============================== The code BELOW will not be graded =============================== /// <summary> /// Adds a readable to the list of readables in case there is no readable with the same id or title. /// </summary> /// <param name="readable">readable to be added</param> public void AddReadable(Readable readable) { foreach (Readable r in readables) { if (r.Id == readable.Id || r.Title == readable.Title) { return; } } readables.Add(readable); }
/// <summary> /// Receives a readable /// </summary> /// <param name="id">ID of the readable to be received</param> public void ReceiveReadable(int id) { Readable r = GetReadable(id); if (r is Book) { if (((Book)r).IsBorrowed()) { ((Book)r).Receive(); } else { throw new NotABorrowableException("The book is already received."); } } else { throw new NotABorrowableException("The readable is not borrowable."); } }
// Provide your answers in the area below. /// <summary> /// Borrows a readable /// </summary> /// <param name="id">ID of the readable to be borrowed</param> /// <param name="name">Name of the borrower</param> public void BorrowReadable(int id, string name) { Readable r = GetReadable(id); if (r is Book) { if (!((Book)r).IsBorrowed()) { ((Book)r).Borrow(name); } else { throw new NotABorrowableException("The book is already borrowed."); } } else { throw new NotABorrowableException("The readable is not borrowable."); } }