0% found this document useful (0 votes)
5 views

Assignment 2 Solution

Uploaded by

bushrayawar928
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Assignment 2 Solution

Uploaded by

bushrayawar928
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PMAS Arid Agriculture University Rawalpindi

University Institute of Information Technology

Visual Programming
Assignment No 2
BSSE – 7A/B
CS-692
Submission Deadline: 22th Nov 2024 (Tuesday – 09:00:AM)
Marks: 10
-----------------------------------------------------------------------------------
Solution
using System;
using System.Collections.Generic;

public abstract class LibraryItem


{
public string Title { get; set; }
public string Category { get; set; }
public abstract void DisplayDetails();
}

public class Book : LibraryItem


{
public int BookID { get; set; }
public string Author { get; set; }
public string ISBN { get; set; }
public string Status { get; set; } = "Available";

public override void DisplayDetails()


{
Console.WriteLine($"Title: {Title}, Author: {Author}, ISBN: {ISBN}, Status:
{Status}");
}

public void GenerateISBN()


{
ISBN = $"{Title.Substring(0, 3).ToUpper()}{Author.Substring(0,
3).ToUpper()}{new Random().Next(1000, 9999)}";
}
}

public interface IBorrowable


{
void BorrowItem(Book book);
void ReturnItem(Book book);
}

public class Person


{
public string Name { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
}

public class LibraryUser : Person, IBorrowable


{
public int UserID { get; set; }
public string MembershipType { get; set; }
private List<Book> BorrowedBooks = new List<Book>();

public void BorrowItem(Book book)


{
PMAS Arid Agriculture University Rawalpindi
University Institute of Information Technology
if (book.Status == "Available")
{
book.Status = "Checked Out";
BorrowedBooks.Add(book);
Console.WriteLine($"{Name} borrowed {book.Title}.");
}
else
{
Console.WriteLine($"{book.Title} is not available.");
}
}

public void ReturnItem(Book book)


{
if (BorrowedBooks.Contains(book))
{
book.Status = "Available";
BorrowedBooks.Remove(book);
Console.WriteLine($"{Name} returned {book.Title}.");
}
}

public void ValidateContactDetails()


{
if (Email.Contains("@") && Email.EndsWith(".com") &&
PhoneNumber.StartsWith("+1"))
{
Console.WriteLine("Contact details are valid.");
}
else
{
Console.WriteLine("Contact details are invalid.");
}
}

public void SearchBooks(List<Book> books, string keyword)


{
foreach (var book in books)
{
if (book.Title.Contains(keyword) || book.Author.Contains(keyword))
{
Console.WriteLine($"Found: {book.Title} by {book.Author}");
}
}
}
}

You might also like