CSC 321: Data Structures
Fall 2012

HW6: Sets & Maps


You have been hired by OKReads, an online book club that encourages members to post reviews of books that they have read. You are to write a program to process book reviews and allow for searches based on a book title or reviewer name. The review logfile will consist of a sequence of reviews, each of which will be three lines long: the first line is the reviewer's name; the second is the title of the book he/she reviewed; the third is the rating he/she gave the book (out of 5). For example, one entry might be

    kingStevie
    Cruise of the Undead
    4.8

Note that it is possible for a reviewer to review the same book more than once. If that is the case, only the last review (i.e., the one that appears latest in the file) should be stored and count in reviewer/book statistics.

Your program should read in and process all of the reviews from a logfile whose name is entered by the user. After all of the reviews have been read and processed, your program should repeatedly prompt the user to enter the name of a reviewer or book. If the user's response matches a reviewer name, then all of the books listed by that reviewer should be displayed (in alphabetical order by title), as well as the average rating given by that reviewer. If the user's response matches a book title, then all of the reviews for that book should be listed (in alphabetical order by reviewer name), as well as the average rating for that book. Averages should all be displayed with one digit to the right of the decimal place.

For example, if the user entered kingStephen, your program might produce:

    kingStevie                  avg rating = 4.1
        Cruise of the Undead    4.8
        Feed                    3.8
        World War Z             3.6

For example, if the user entered Cruise of the Undead, your program might produce:

    Cruise of the Undead        avg rating = 3.8
        eapoe                   4.9
        helloKitty              1.0
        kingStevie              4.8
        scaredyCat              4.5

Your program should only read the logifle once, storing and organizing the information as necessary. It should be able to find and display the books for a particular reviewer in at worst O(B log R), where R is the number of reviewers and B is the number of books read by the reviewer. Likewise, it should be able to find and display all of the reviewers for a particular book in at most O(R log B).

As with previous homeworks, you must demonstrate good programming style when completing this assignment, including the appropriate use of Javadoc-style comments for all classes and methods. The interface for your program is entirely up to you. It need not be fancy, but it must at least allow the user to enter a file name, repeatedly enter reviewers/books and view the results.