Answered Essay: Your submission should include hard copies of all 3 classes and the output from running the program using the follo

Write a console application to meet the following requirements.  Create a system for a simple library.  The library has a name and a list of books.  Each book has a title, author and an int as the id number.  Define classes for both the library and the book.  The library should have methods for adding a book to the library, to search for a book by title, to sort and display information about all of the books and to delete a book (by title) from the library.  You will need to write 3 sort methods.  One for sorting by title, one for sorting by author and one for sorting by idnum.  Each sort must use a different process, i.e. one uses a bubble sort, one uses a selection sort and one uses an insertion sort.

The following conditions apply to the books in the library:

Each book�s name is unique.  There are no duplicate titles. When adding a book, ensure that the title doesn�t already exist.  If it does exist, don�t let the new book be added.

There is only one copy of each book in the library.

An author may have more than one book in the library.

Complete the code in this incomplete client designed to test the classes and their functionality.  You should not change any of the other code in main.

class MainClass

{

public static void Main (string[] args)

{

Library lib = new Library ();

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’:

//insert code here for adding a book

break;

case ‘S’:

//insert code here for finding a book and

//printing its details

break;

case ‘D’:

//insert code here for displaying all of the books in the library

// alphabetically by title

break;

case ‘E’:

//insert code here for displaying all of the books in the library

// alphabetically by author

break;

case ‘F’:

//insert code here for displaying all of the books in the library

// in ascending order by id num

break;

case ‘R’:

//insert code here for removing a book                                                                         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: “);

 

}

}

Your submission should include hard copies of all 3 classes and the output from running the program using the following options:  D, A ( add a book of your own), e, s for a book in the library, s for a book not in the library, r for a book in the library, r for a book not in the library, f, and q.

Expert Answer

 

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
Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.