Question: This is a simulation of code demonstrating students getting in line (queue) and getting a book at the book store (from a stack). You will
This is a simulation of code demonstrating students getting in line (queue) and getting a book at the book store (from a stack).
You will create a simple Student class and a simple Book class. Next, you will build sorted lists of 10 unique Students and 10 unique Books. You will then iterate through each sorted list and add Students to a queue (enqueue), which simulates a line at a Bookstore, and you will add Books (push) to a Stack, simulating a stack of books. Using a Queue and a Stack, you will demonstrate students getting in line and taking a book off of the stack.
The first student in line will be helped (dequeued) and will be given the top book in the stack (Pop). This book elicitation is simulated by setting the Book property of Student. After that first student gets a book, we move to the next student in line - the next student will get his/her book like the first student, did, and get out of the line. This continues until all 10 students and all 10 books are processed (each student gets Book property set).
Detailed instructions:
1) Create a class Book with public properties of Title and Number. You only need to implement properties and a default constructor. No methods are required but feel free to add any which may help.
2) Create a class Student with public properties of Title, Number, and Book. You only need to implement properties and a default constructor. No methods are required but feel free to add any which may help.
3) Create 10 instances of student with unique LastName property set. Add them to a sorted list with the LastName property being the key and the value being the entire Student object. HINT: the type would be SortedList
4) Create 10 instances of Book with unique (int) Number for each book. Add them to a sorted list with the Number being the the key and the value being the Book object. HINT: the type would be SortedList
5) Iterate through each Student in the SortedList and add them to a Queue. Iterate another way of saying "use a loop."
6) Iterate through each Book and add them to a Stack.
7) Now iterate through the student queue using a loop. Dequeue each student. Use the student instance returned by Dequeue and set the Book property of the dequeued student to the Book that is on the top of the stack, using the Stack's Pop method.
8) Using Console.WriteLine(), show each Student's First name, last name, book number, and book title. End the program by adding Console.ReadKey() to the end.
You do not have use Console.ReadLine to collect user input from the Console. Don't add functionality that isn't specifically required above, it will not earn you any extra points.
Set properties in code using loops and string modifications to make things unique. This is a time saver for you. You do not have to implement any methods/behaviors in your Student and Book classes, unless you want to. Your Student and Book classes just need properties and a default constructor.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
