gay
unknown
plain_text
12 days ago
3.7 kB
6
Indexable
Never
using System; namespace LibraryApplication { // Book class to store book details class Book { public string Title { get; set; } public string Author { get; set; } public bool IsAvailable { get; set; } public Book(string title, string author, bool isAvailable) { Title = title; Author = author; IsAvailable = isAvailable; } } // LibraryMember class to store member details and methods to interact with books class LibraryMember { public string Name { get; set; } public int MemberID { get; set; } public LibraryMember(string name, int memberId) { Name = name; MemberID = memberId; } // Method to show books and their availability public void ShowBooks(Book[] books) { Console.WriteLine("Books available in the library:"); for (int i = 0; i < books.Length; i++) { Console.WriteLine($"{i + 1}. {books[i].Title} by {books[i].Author} - {(books[i].IsAvailable ? "Available" : "Not Available")}"); } } // Method to rent a book if available public void RentBook(Book[] books, int bookIndex) { if (books[bookIndex].IsAvailable) { books[bookIndex].IsAvailable = false; Console.WriteLine($"You have rented '{books[bookIndex].Title}' by {books[bookIndex].Author}"); } else { Console.WriteLine($"Sorry, '{books[bookIndex].Title}' is currently not available."); } } } // Librarian class to store librarian details class Librarian { public string Name { get; set; } public string EmployeeID { get; set; } public Librarian(string name, string employeeId) { Name = name; EmployeeID = employeeId; } } // Library class to manage books and members class Library { public Book[] Books; public LibraryMember[] Members; public Library(Book[] books, LibraryMember[] members) { Books = books; Members = members; } } // Main class class Program { static void Main(string[] args) { // Creating books array Book[] books = new Book[] { new Book("1984", "George Orwell", true), new Book("To Kill a Mockingbird", "Harper Lee", true), new Book("The Great Gatsby", "F. Scott Fitzgerald", false) }; // Creating members array LibraryMember[] members = new LibraryMember[] { new LibraryMember("John Doe", 1), new LibraryMember("Jane Smith", 2) }; // Creating the library Library library = new Library(books, members); // Display books and rent one as a demonstration LibraryMember member = members[0]; // Let's say John Doe is interacting member.ShowBooks(library.Books); // Show available books Console.WriteLine("Enter the number of the book you want to rent: "); int selectedBook = int.Parse(Console.ReadLine()) - 1; member.RentBook(library.Books, selectedBook); // Rent the selected book // Show books after renting member.ShowBooks(library.Books); Console.ReadLine(); } } }
Leave a Comment