using System.Collections.Generic;
public bool IsBorrowed { get; set; }
public Book(string title, string author, string isbn)
if (string.IsNullOrWhiteSpace(value))
throw new ArgumentException("Title cannot be empty.");
title = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(title);
if (string.IsNullOrWhiteSpace(value))
throw new ArgumentException("Author cannot be empty.");
author = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(author);
if (string.IsNullOrWhiteSpace(value))
throw new ArgumentException("ISBN cannot be empty.");
public virtual void DisplayMessage()
Console.WriteLine("This is a catalog.");
public class Library : Catalog
private List<Book> books;
books = new List<Book>();
Console.Write("Enter book title: ");
string title = Console.ReadLine();
Console.Write("Enter book author: ");
string author = Console.ReadLine();
Console.Write("Enter book ISBN: ");
string isbn = Console.ReadLine();
Book book = new Book(title, author, isbn);
Console.WriteLine("Book added successfully!");
public void DisplayBooks()
foreach (Book book in books)
Console.WriteLine("Title: " + book.Title + ", Author: " + book.Author + ", ISBN: " + book.ISBN);
public Book SearchBookByTitle(string title)
return books.Find(book => book.Title.ToLower() == title.ToLower().Trim());
public Book SearchBookByAuthor(string author)
return books.Find(book => book.Author.ToLower() == author.ToLower().Trim());
public void DeleteBook(string isbn)
Book book = books.Find(b => b.ISBN == isbn);
Console.WriteLine("Book deleted successfully!");
Console.WriteLine("Book not found.");
books = books.OrderBy(b => b.Title).ToList();
Console.WriteLine("Books sorted by title.");
public void BorrowBook(string isbn)
Book book = books.Find(b => b.ISBN == isbn);
Console.WriteLine("Book borrowed successfully!");
Console.WriteLine("Book is already borrowed.");
Console.WriteLine("Book not found.");
public void ReturnBook(string isbn)
Book book = books.Find(b => b.ISBN == isbn);
Console.WriteLine("Book returned successfully!");
Console.WriteLine("Book is not borrowed.");
Console.WriteLine("Book not found.");
public override void DisplayMessage()
Console.WriteLine("This is a library catalog.");
public static void Main(string[] args)
Library library = new Library();
Console.WriteLine("1. Add book");
Console.WriteLine("2. Display books");
Console.WriteLine("3. Search book by title");
Console.WriteLine("4. Search book by author");
Console.WriteLine("5. Delete book");
Console.WriteLine("6. Sort books");
Console.WriteLine("7. Borrow book");
Console.WriteLine("8. Return book");
Console.WriteLine("9. Exit");
Console.Write("Enter your choice: ");
int choice = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter title: ");
string title = Console.ReadLine();
Book bookByTitle = library.SearchBookByTitle(title);
Console.WriteLine("Book found! Title: " + bookByTitle.Title + ", Author: " + bookByTitle.Author + ", ISBN: " + bookByTitle.ISBN);
Console.WriteLine("Book not found.");
Console.Write("Enter author: ");
string author = Console.ReadLine();
Book bookByAuthor = library.SearchBookByAuthor(author);
if (bookByAuthor != null)
Console.WriteLine("Book found! Title: " + bookByAuthor.Title + ", Author: " + bookByAuthor.Author + ", ISBN: " + bookByAuthor.ISBN);
Console.WriteLine("Book not found.");
Console.Write("Enter ISBN of the book to delete: ");
string isbnToDelete = Console.ReadLine();
library.DeleteBook(isbnToDelete);
Console.Write("Enter ISBN of the book to borrow: ");
string isbnToBorrow = Console.ReadLine();
library.BorrowBook(isbnToBorrow);
Console.Write("Enter ISBN of the book to return: ");
string isbnToReturn = Console.ReadLine();
library.ReturnBook(isbnToReturn);
Console.WriteLine("Invalid choice.");