Below is your program. Let me know if you have any issue in comments
using System;
using System.Collections.Generic;
using System.Linq;
namespace MainClass
{
class MainClass
{
public static void Main (string[] args)
{
Library lib = new Library(“Library 1”);
lib.AddBook (“C# programming”, “Gesick”, 4);
lib.AddBook (“java programming”, “Roth”, 2);
lib.AddBook (“C++ programming”, “Franklin”, 1);
lib.AddBook (“unity programming”, “Preston”, 3);
lib.AddBook (“graphics & multimedia”, “Chastine”, 5);
printMenu ();
string p = Console.ReadLine ();
p = p.ToUpper ();
char pick = p [0];
while (pick!=’Q’) {
switch (pick) {
case ‘A’:
Console.WriteLine (“Please insert a title for the new book.”);
string t = Console.ReadLine();
int ab = Library.Search(t);
if(ab == -1)
{
Console.WriteLine (“Please insert an author for the new book.”);
string a = Console.ReadLine();
int numb = Library.GetBookCount();
lib.AddBook (t, a, numb + 1);
Console.WriteLine(“Book successfully added!”);
}
else
{
Console.WriteLine (“Book title already exists!”);
break;
}
break;
case ‘S’:
Console.WriteLine (“Please type a book title to search: “);
string s = Console.ReadLine ();
int result = Library.Search(s);
if(result == -1)
{
Console.WriteLine(“Book not found.”);
}
break;
case ‘D’:
Console.WriteLine(lib.ToStringTitle());
break;
case ‘E’:
Console.WriteLine(lib.ToStringAuthor());
break;
case ‘F’:
Console.WriteLine(lib.ToStringID());
break;
case ‘R’:
Console.WriteLine (“Please type a book title to remove: “);
string y = Console.ReadLine ();
Library.RemoveBook(y);
Console.WriteLine (“Book successfully removed!”);
break;
default:
Console.WriteLine (“nInvalid choice, please re-enter”);
break;
}
printMenu ();
p = Console.ReadLine ();
p = p.ToUpper ();
pick = p [0];
}
Console.WriteLine (“good bye”);
}
public static void printMenu ()
{
Console.WriteLine (“nSelect one of the following:nn” +
” A to add a book to the libraryn” +
” S to search for a book by titlen” +
” D to display the contents of the library, alphabetically by title n” +
” E to display the contents of the library, alphabetically by author n” +
” F to display the contents of the library, in ascending order by id num n” +
” R to remove a book from the libraryn” +
” Q to quit this programnn”);
Console.Write (“enter choice here: “);
}
}
public class Library
{
private string libName;
static List<Book> bookTitles = new List<Book>();
public Library(string x)
{
libName = x;
}
public void AddBook(string t, string a, int ident)
{
Book book = new Book (t, a, ident);
bookTitles.Add (book);
}
public override string ToString()
{
string h = “”;
foreach (Book z in bookTitles) {
h += z.ToString ();
h += “n”;
}
return h;
}
public string ToStringTitle()
{
string h = “”;
var sortedList = bookTitles.OrderBy(x => x.getTitle()).ToList();
foreach (Book z in sortedList) {
h += z.ToString ();
h += “n”;
}
return h;
}
public string ToStringAuthor()
{
string h = “”;
var sortedList = bookTitles.OrderBy(x => x.getAuthor()).ToList();
foreach (Book z in sortedList) {
h += z.ToString2 ();
h += “n”;
}
return h;
}
public string ToStringID()
{
string h = “”;
var sortedList = bookTitles.OrderBy(x => x.getID()).ToList();
foreach (Book z in sortedList) {
h += z.ToString2 ();
h += “n”;
}
return h;
}
public static int Search(string title)
{
for (int i=0; i<= bookTitles.Count – 1; i++)
{
if(title == bookTitles[i].ToString())
{
Console.WriteLine (bookTitles[i].ToString2());
return i;
}
}
return -1;
}
public static void RemoveBook(string title)
{
for (int i=0; i<= bookTitles.Count – 1; i++)
{
if(title == bookTitles[i].ToString())
{
bookTitles.RemoveAt (i);
}
}
}
public static int GetBookCount()
{
return bookTitles.Count;
}
}
public class Book
{
private string title;
private string author;
private int ID;
public Book(string a, string b, int c)
{
title = a;
author = b;
ID = c;
}
public string getTitle() {
return title;
}
public string getAuthor() {
return author;
}
public int getID() {
return ID;
}
public override string ToString()
{
return title;
}
public string ToString2()
{
return title + ” by ” + author + ” with ID ” + ID;
}
}
}
Sample Run
Select one of the following:
A to add a book to the library
S to search for a book by title
D to display the contents of the library, alphabetically by title
E to display the contents of the library, alphabetically by author
F to display the contents of the library, in ascending order by id num
R to remove a book from the library
Q to quit this program
enter choice here: A
Please insert a title for the new book.
Harry Potter
Please insert an author for the new book.
Rowling
Book successfully added!
Select one of the following:
A to add a book to the library
S to search for a book by title
D to display the contents of the library, alphabetically by title
E to display the contents of the library, alphabetically by author
F to display the contents of the library, in ascending order by id num
R to remove a book from the library
Q to quit this program
enter choice here: S
Please type a book title to search:
Harry Potter
Harry Potter by Rowling with ID 6
Select one of the following:
A to add a book to the library
S to search for a book by title
D to display the contents of the library, alphabetically by title
E to display the contents of the library, alphabetically by author
F to display the contents of the library, in ascending order by id num
R to remove a book from the library
Q to quit this program
enter choice here: D
C# programming
C++ programming
graphics & multimedia
Harry Potter
java programming
unity programming
Select one of the following:
A to add a book to the library
S to search for a book by title
D to display the contents of the library, alphabetically by title
E to display the contents of the library, alphabetically by author
F to display the contents of the library, in ascending order by id num
R to remove a book from the library
Q to quit this program
enter choice here: E
graphics & multimedia by Chastine with ID 5
C++ programming by Franklin with ID 1
C# programming by Gesick with ID 4
unity programming by Preston with ID 3
java programming by Roth with ID 2
Harry Potter by Rowling with ID 6
Select one of the following:
A to add a book to the library
S to search for a book by title
D to display the contents of the library, alphabetically by title
E to display the contents of the library, alphabetically by author
F to display the contents of the library, in ascending order by id num
R to remove a book from the library
Q to quit this program
enter choice here: F
C++ programming by Franklin with ID 1
java programming by Roth with ID 2
unity programming by Preston with ID 3
C# programming by Gesick with ID 4
graphics & multimedia by Chastine with ID 5
Harry Potter by Rowling with ID 6
Select one of the following:
A to add a book to the library
S to search for a book by title
D to display the contents of the library, alphabetically by title
E to display the contents of the library, alphabetically by author
F to display the contents of the library, in ascending order by id num
R to remove a book from the library
Q to quit this program
enter choice here: R
Please type a book title to remove:
Harry Potter
Book successfully removed!
Select one of the following:
A to add a book to the library
S to search for a book by title
D to display the contents of the library, alphabetically by title
E to display the contents of the library, alphabetically by author
F to display the contents of the library, in ascending order by id num
R to remove a book from the library
Q to quit this program
enter choice here: D
C# programming
C++ programming
graphics & multimedia
java programming
unity programming
Select one of the following:
A to add a book to the library
S to search for a book by title
D to display the contents of the library, alphabetically by title
E to display the contents of the library, alphabetically by author
F to display the contents of the library, in ascending order by id num
R to remove a book from the library
Q to quit this program
enter choice here: Q
good bye