|
Course Description Syllabus Reading List Team Project |
Homework 2Last updated: Sept 29, 2006 6:45 pm 1. Adding a publisher for the Book (20 points)In this part, you will extend the library program to include a publisher class. You will create the new class, its constructor methods, set and get methods, and one helper method (equals). Start with files from the solution to exercise 3, part 3 (Book.java, Size.java, and Library.java). First, create a new class called Publisher, which will contain the publisher name, city, state, and country as instance variables. We'll code the class first, and then modify the Book class to include a Publisher for every Book. Remember: Each class goes in its own file. The file name must match the name of the class that is in that file. For example, Book.java contains the Book class -- nothing else. If you use the Eclipse class wizard, it will do this for you automatically. Create two constructors, one that takes no arguments, and one that takes four arguments (name, city, state, and country). Create the get and set methods, too. Now define a helper method to determine whether two different books have the same publisher. As usual, lets call it "equals". Look at how this was done for Book and Size, and it should be pretty clear how to do it for Publisher. Once you are done with this, create a main method in the Publisher class to demonstrate the use of both constructors and the equals method. The next step is to add a Publisher to each Book. We'll do this by first declaring a publisher instance variable in the Book class, and then modifying the Book class's constructor to create a Publisher for each book. Don't forget to modify the equals class to compare publishers (using the Publisher equals() method). Finally, modify the Library main method to create two publishers, O'Reilly and Random House. Use O'Reilly for the first 2 books and Random House for the third. Modify the rest of the main() method to demonstrate a successful result from the search function, as well as an unsuccessful search result. 2. Keeping track of the number of books owned (20 points)In this part, you will enhance the Book class to keep track of the number of books owned. Here is a checklist of things to do:
Submitting your homeworkTo submit your homework, export your files from Eclipse, create a ZIP archive of them, and email that as an attachment to both the TA and me (to ensure that one of us gets it). To export a file, use the File/Export wizard. Choose "File System" as the export destination, and click Next. Select the directories (on the upper left) or files (upper right) you want to export and enter or browse to the target directory, and click Finish. Homework submitted after the deadline (Thursday @ 6:00) will not be graded (since the solutions will be posted), so it is a sure thing that you would be better off to send something on time rather than to sending nothing in the hopes that you might have something better later. Be sure to read the instructions about working together on homework on the course description Web page if you have any questions about what sort of collaboration is allowed. Bill Kules |