CSE142 Spring 2004

Assignment 4

Movie Data Base

Due Dates: see below

You will expand your experience using loops and conditionals and use an ArrayList to store information (store a sequence).  In addition, you will do some test creation.  The assignment is similar in spirit and even in some details to Assigment 3.   When you are done, you will have classes that can display and answer questions about movies.

The Warm-up covers some basics of getting ready. In the Opener, you write a class to keep information on one movie, a movie record, and write part of a class to store and analyze a collection of these records. In the Headliner, you extend the system. 

Pairs vs. Solo: The Warm-Up and Opener are meant to be doable by individuals.  If your TA has not assigned a new partner, or if you cannot quickly contact your partner, do the Opener alone.  For the Headliner you should work with your new partner.

Warm-up

So that you can develop an application to examine movie information, you are provided with a class to help you read some real movie data from disk. To get started, look to see what files are available here.  For convenience, the files are also available in a .zip file (use that if you are comfortable with using .zip files already; instructions are not provided).   From that location, you need the three .class files DelimitedTextReader.class, DelimitedTextFile.class, and MVFieldReader.class.  Put them in the folder where you are going to put your new .java files for this project.  You will also need some data files, which should go in the same directory.  For now, download the mvShort.txt file to use with the first part of the project.  Eventually for the Headliner there may be additional .txt files, in this directory or in others you will be told about.

The .txt file contains a small amount of movie data. You can open and view it as you would any text file. You will not have to write code to process it directly!  The MVFieldReader class will help you extract data from it.

As you did in assignment 3, create and save an empty file called MovieRecord.java (go back to the Assignment 3 instructions if you don't remember how you did this).  It MUST be in the same directory as the files downloaded above.
After you've downloaded the files and created MovieRecord.java, 'Compile All'   .

The empty file should compile without any problems, if it doesn't, get help. Now in the interactions pane, type:

      MVFieldReader reader = new MVFieldReader("mvShort.txt");

If you get an error, go back and reread the instructions, or ask for help. You won't be able to do the rest of the assignment without this working.

Now that you have the .class files properly placed, you'll start the assignment by examining some movie data. To allow you to easily read the data from the files, the MVFieldReader class is provided. Check out the documentation to get to know the operations available for MVFieldReader. Go browse the documentation now, you'll find there is not much to get familiar with. The "getNextField" method allows you to get the information, one field at a time. When you use the "getNextField" method, the next field is returned to you (as a String). The movie data of the .txt file consists of many lines of information about movies. The format of each line is the same. There are six fields of information each line, including

Each field of information is terminated ("delimited", to use a fancier word) from the rest by a slash, '/' .   For example:

   Lord of the Rings/Peter Jackson/2001/Noel Appleby/Sean Astin/Sala Baker/

When you use "getNextField" of the MVFieldReader class, you must invoke it the correct number of times to get all the proper information. For the above data, the first time it is called, getNextField returns a String containing "Lord of the Rings" .   The second time it is called, it returns a String containing "Peter Jackson" ...  and so on through "Sala Baker".  The next six invocations after that would get the six fields from the next line of the text file.

Try a few things out and answer the following questions in a file called   warmup.txt .

  1. In the interactions pane create a new instance of   MVFieldReader   using the file "mvShort.txt" . Use System.out.println to print this object: what do you see?
  2.  Use the   getNextField   method of your instance to retrieve the first field of the first line, a   String.     This represents the title of the movie.  What is the title?
  3. Who is the director of the movie?   (Of course, you should answer this by using your MVFieldReader instance, not by looking at the text file!)
  4. When was the movie made?
  5. Who are the three major actors?
  6. What are the titles of the next two movies?
  7. How many movies in total are in this file?

To show that you understand exactly what the movie data looks like, create your own file called mvfav.txt. Put data in the correct format for two of you and your partner's favorite movies (unless your favorite movie happens to be a movie in mvShort.txt, then choose another).  After creating the file, try it out!  Repeat the steps above, this time using "mvfav.txt" for constructiong the MVFieldReader. 

If some of the steps fail, it probably indicates an error or omission in your file format.  Correct the error and start over -- keep trying until you can get through all the steps.  This file will need to be turned in, by the way.  (If you are interested in creating an interesting, substantial and useful data file of movies to share with others, there will be an opportunity to earn service/participation points... more about this at a later time.)

Opener

Electronic due Thursday, May 6 at 10pm (MovieRecord.java, warmup.txt, and mvfav.txt). Paperwork is due in class the next day.   (Remember one turn-in per team.)

You already created a blank MovieRecord.java file in the warm-up; now write the MovieRecord class to store information on a single movie including title, director, year, and three prominent actors. Provide the constructor and methods to get the information:

After creating your class, test it out in the DrJava Interactions pane.  Create a couple of MovieRecord objects. How can you verify that your class is correct?   Then create an empty ArrayList and add the MovieRecord objects to it.  How can you verify the contents of the list?  ArrayLists of MovieRecords will be important in the next part of the project, so be sure you are comfortable with using those two classes together.

Headliner

Electronic due Wednesday, May 12 at 10pm (MovieRecord again,  MovieReporter, and chorus.txt).  (Remember one turn-in per team.)  Paperwork is due in class the next day. Turn in your individual encore paragraph as well.   Be sure to put your quiz section on your paper.

The MovieRecord class stores information on an individual movie, but another class is needed to manage a collection of movies. Write a class called   MovieReporter that will do this.  The idea is that MovieReporter will internally have an ArrayList storing many MovieRecord references to objects.

Provide the following constructors and methods:

Once you have at least one constructor and the printMovieCollection object, you can do quite a bit of testing of your class.  Test using various data files.  You don't know which one might be used during grading!

Then add more methods to your MovieReporter class.   Be careful to not repeat code unnecessarily ... instead, reuse methods. And thoroughly test all methods under all conditions, and tested with different data files. Add the following methods to MovieReporter:

Note that for this part of the assignment, there are no required additions to MovieRecord.  However, it is possible that you may find things to be corrected in your orignal version of the class.  For that reason, the MovieRecord.java should be turned-in again

Comparing Assignment 3 and Assignment 4: Your MovieRecord object is similar in nature to the StudentData object of assignment 3. The ArrayList inside MovieReporter takes on the role of the BasicClassList. The MovieReporter analyzes MovieRecord objects in a manner similar to how the ClassListAnalyzer analyzed StudentData objects.   There is nothing in Assignment 4 corresponding to the DataPortal.

Chorus

Discuss the following questions with you partner and answer them in a file called chorus.txt.

  1. Think back to assignment 3. What can you guess about the use of ArrayLists in the BasicClassList?
  2. What are some reasons why MovieRecord and MovieReporter are two separate classes instead on one big class?
  3. Could MovieReporter have been designed to have several ArrayLists, one that would hold all the titles, one that would hold all the directors, one with all the years, etc.?  Would that be better or worse than the way it was actually done?
  4. Without writing any new methods, how would you do the following (in the Interactions pane, in just a few lines): Given a year, print a list of all the movies for that year, pausing after each 20 lines...
  5. Think up an additional method for MovieReporter -- one which provides information that you and your partner think would be interesting to have for a movie database.  It should be something that can be answered given the type of data available.  Don't program your method -- just explain what it would do.

Encore

On your own (separate from your partner) write a short paragraph about your pair-programming experience.

      What worked well, what didn't?
      How well was the work shared between you?
      Was there anything particularly challenging about this assignment?   If so, what?

Hand in this write-up at the same time as the other paperwork for the assgnment..