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
- a title
- director
- year
- three primary actors
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 .
- 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?
- 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?
- 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!)
- When was the movie made?
- Who are the three major actors?
- What are the titles of the next two movies?
- 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:
- A constructor that takes the title, director, year, and
three actors (in that order). All are String types except year which is
of type int.
- A method getTitle that returns
the movie title, a String type.
- A method getDirector that returns
the movie director, a String type.
- A method getYear that returns the
year the movie was made, an int type.
- A method getActor1 that returns
the first prominent actor, a String type.
- A method getActor2 that returns
the second actor, a String type.
- A method getActor3 that returns
the third actor, a String type.
- A method toString that returns
all the movie data as one one
String object, with a nice readable
format. Put the fields in this order: year, title, director,
actor1, actor2, actor3.
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:
- A constructor which has one String
parameter, the name of a .txt file containing the movie data. You will
create a MVFieldReader object, and use the
getNextField of MVFieldReader get movie information; using that
information,
fill up the ArrayList with MovieRecord
objects, one per movie. Note that the year field as it comes from
getNextField is a string, but the year parameter of the MovieRecord
constructor is an int. To convert a String, say s, to an
int, use the following code (experiment in the DrJava Interactions pane
to see how it works):
Integer intObj = new Integer(s);
// converts s to Integer object
int n = intObj.intValue();
// extract the int
value from the object
- A constructor which takes an
ArrayList parameter; the ArrayList is assumed to contain MovieRecord
objects.
- The printMovieCollection method prints all the
stored values for each movie data item, one movie per line. This method
has no parameters, no return value.
-- Since there could be many movies, pause after each 20
lines
and ask the user whether or not to continue.
-- Use the following standard order for the data (keep it
to one line): year, title, director, the three
actors
Hint: could the toString method of
MovieRecord
be helpful here?
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:
- A method getSize that returns the
number of movie records stored.
- A method directorOfMost that
returns the director who made the most movies.
- A method filterByYear that takes
an int parameter representing a year and returns an ArrayList object
containing all the MovieRecords of movies of that year.
- A method filterByYear that
takes two int parameters
representing a starting and ending year in a
range and returns an ArrayList of all MovieRecords of movies for any of
those years.
- A method findCostarMovies that
takes an actor (String type), say x. Given this actor, x, within the
method, create an ArrayList of all the co-stars who acted in movies
with x. Then return an ArrayList of all movies in which any of those
people acted.
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.
- Think back to assignment 3. What can you guess about the use of
ArrayLists in the BasicClassList?
- What are some reasons why MovieRecord and MovieReporter are two
separate
classes instead on one big class?
- 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?
- 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...
- 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..