Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Data Structure The data structure you will be using for this program will be an array of records where each record in the array represents

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Data Structure The data structure you will be using for this program will be an array of records where each record in the array represents one book and each of the components within the record are the book fields. Feel free to use an ArrayList as opposed to a traditional array. If you use a traditional array, you may assume the input size will never exceed 50. Each book record should have the following five fields set up in this order: 1. Title - a string object 2. Author's Name (Last Name, First Name) - a string object 3. Copyright 4. Price 5. Genre (fiction, nonfiction, drama, poetry) - an enumerated type It would probably be best to develop a class, say LibraryBook, that contains each of these as private attributes and includes public getter methods to access each of them. org Opening the Input File You will need a method to allow the user to input all book records currently stored in the library's database file. This database file is an external file with a .dat extension whose name you will prompt for at run-time. You should provide the user with a listing of the data files in the current directory they can choose. Inputting your Book Records Within your input method, you will also want to input all the fields of your book records. You may assume the format shown in your input file will always be the same. You will need to use a while not end of file loop rather than a for loop to set up each of your book records since you will not know how many slots there are to fill. After inputting your library data, you will need to call a method to sort it (see below on coding this method). The total number of records that have now been input and sorted should then be printed to the screen with a prompt such as the following: A total of 4 books have been input and sorted by title. Before leaving this method, you can let the user continue the program at their own pace by using a please hit return to continue. Sorting The input data should be sorted using the selection sort algorithm. You will need to slightly modify the headings of your selection sort code we went over in class so that it includes the number of books as an input parameter. The reason for this is that not all of the slots in our 50-slot array will be used. You will also be sending in an array of records rather than an array of integers. You will also need to tweak a few other things. Your temporary variable used for swapping will need to be of the book record type. Also, you're not comparing entire array slots, you are comparing title fields within those array slots. Menu for Program Following the input and sort, the user should be able to continue searching for book records until they are ready to quit. Call a method that prints a menu such as the following: THE GREAT BOOKS SEARCH PROGRAM 1) 2) 3) Display all book records Search for a book by Title Exit Search Program Please Enter Your Choice > This method should return the user's menu selection to the main program which will utilize the user's choice in a switch statement. The selection variable should be an integer and will only take on the values of 1 through 3. The user should receive an error message if they enter any integer value other than these three. Searching You will have a method which prompts the user for the title they are searching for, and then calls a search method to see if this title is in your array of book records. A binary search is ideal here since we have a sorted array and it will be quicker than a linear search. If the book title is found, the corresponding book record should be displayed by calling a method to print the record at the found location. Otherwise, they should be informed that the book was not found. Displaying and Printing Records You should have a method displayRecords that is called to display all your book records. This method should use a for loop to call a printRecord method that is used to print out a book record by its record number. For example, for (int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions