Question
For this task you have been provided with a simple 'Book' class, which represents information about a book including its title and topics. Your task
For this task you have been provided with a simple 'Book' class, which represents information about a book including its title and topics. Your task in this exercise is to create a 'BookCollection' class that represents a collection of books and allows the collection to be searched based on the topics of the books.
The code for the 'Book' class is provided as part of the sample code. You should not touch this code; instead, write your own 'BookCollection' class according to the specification below.
The 'BookCollection' class must have 2 constructors:
public BookCollection()
This constructor creates an empty BookCollection.
public BookCollection(List
This constructor creates a collection of books with the provided list of books included.
The class must also have several other methods which allow for adding books and finding books with topics:
public void AddBook(Book book)
This method should add a book to the collection. Note - usually this method would check whether the book was already in the collection, however this method has been simplified for this exercise.
public List
This method should return the collection of books.
public List
This method should find books which contain the topic topic. It should return a list of the titles of the books which contain the topic. It is recommended that you implement this method before the following two.
public List
This method should find books which contain any of the topics in the list topics. For example, if the list of topics is ["fantasy", "science"] it should return any book with the topic fantasy OR science. It should return a list of the titles of the books which contain any of the topics. You may want to make use of the BooksWithTopic method here.
public List
This method should find books which contain all of the topics in the list topics. For example, if the list of topics is ["fantasy", "science"] it should return any book with the topic fantasy AND science. It should return a list of the titles of the books which contain all of the topics. You may want to make use of the BooksWithTopic method here.
Sample Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace BookFinder { ///
///
///
public class BookCollection { private List
/// Implement your BookCollection class here
}
///
// Some simple test cases are included here - you may want to test more. // The AMS will not use the same test cases. // Check for single topic: string topic = "fantasy"; List
// Check for any of several topics string[] topics = new string[] { "science", "fiction" }; results = library.BooksWithAnyTopic(topics); // Display results
// Check for all of several topics results = library.BooksWithAllTopics(topics); // Display results
// Exit Console.WriteLine(" Press enter to exit."); Console.ReadLine(); }
// You might want to write some simple helper methods for displaying lists here // (Remember DRY [Don't Repeat Yourself]- if you're writing the same chunk of code // over and over, it should probably be a method!)
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started