CSC236 Data Structures in Java
Lab 3

The New York Times newspaper has published "best seller" lists since 1942. Book sales are tracked nationwide, leading to a list of those books which have recently sold the most copies. You will design, implement and test a program which allows the user to search a subset of the books which have appeared in the New York Times best seller lists. For simplicity, the data set will only contain those books which have reached #1 on either of two lists (fiction and nonfiction) from 1942. Our data only extends through 2013.

Input

The file named bestsellers.txt contains the data set. Each line of the file contains the information for a separate book, which includes: title, author first name, author last name, publisher, date it first reached #1 on one of the best seller lists, and category (fiction or nonfiction). There is a tab character between fields.

Book Class

Create a Book class with the following information: title, author first name, author last name, publisher, date it first reached #1 on one of the best seller lists, and category (fiction or nonfiction). Book will need an equals method and it will need to implement the Comparable Interface and have a compareTo method that will be able to compare Book objects by author last name, first name, and then title. Make sure that a book displays on one line in a nicely formatted, readable manner. Displaying each book on one line will create a table format when a list of books is printed. Use printf to create columns for the fields of a book. Include any other methods necessary to complete this assignment however, only include methods that are needed. Don't write a lot of get methods! Instead, figure out what you need to do with the book fields, and do it in the book methods rather than writing a get and doing it in the bestseller method or client code. For example, if you need to test the value of a field (e.g. does the month match?), pass the month as a parm to a method that compares the parm and the month field of the book. The method should return a boolean that tells whether the month in the Book is the same as the parm.

Date Class

Create a Date class with the following information: month, day, and year. Date needs an equals method and it will need to implement the Comparable Interface and have a compareTo method that will be able to compare Date objects appropriately. Include any other methods necessary to complete this assignment however, only include methods that are needed. Include a constructor that takes the date as a String, in mm/dd/yy format. Again, don't write a lot of get methods! Instead, figure out what you need to do with the date fields, and do it in the date methods rather than writing a get and doing it in the book method, the bestseller method, or the client code. If you need to test the value of a field (e.g. does the month match?), write a method with a parm for the month, and return a boolean that tells whether the month in the Date is the same.

Bestsellers Class

The class BestSellers will hold the information about all the books on the NY Times Best Sellers List. A BestSellers object will contain a SortedArrayCollection of Book objects. The Books will be ordered by author last name, author first name and title.

You will need to add an Iterator to the SortedArrayCollection. The Iterator should be implemented as an anonymous inner class.

The class BestSellers will need methods for the following:

Client Code

Your main program will create a BestSellers object. Prompt for the file name, read the input file, and store the data in your BestSellers object. Then main should give the user a menu so they can perform the lookup tasks stated above. You don't need an option to add a book, that method is used when reading the bestseller file. Let the user continue until they want to quit. If the user gives an invalid response to the menu, give an error message and reprompt until they give a valid response. Print an error message if no books match a search request.

Do not write a giant main function. Have main call some other functions to complete the client code requirements.



Email Me | Office Hours | My Home Page | Department Home | MCC Home Page