Homework 14



Due: 11:59pm on Sunday, December 19, 2004



1 problem, 50 points



Download Hw14Pr1.zip from the "Files for Download Page"
Although you have already started this program, it would be a good idea to download the Hw14Pr1.zip file, unzip it, and then copy your already-written code into the CS5App.java file. The reason for this is that we have included a "starter" database file and some additional code in Hw14Pr1.zip.



Pair Programming Problem
We encourage you to work with a partner on this problem --
it is the largest of the software projects this semester, and the extra pair of eyes helps!





In this project you will implement a film information system inspired by the Internet Movie Database http://www.imdb.com. For each film, you will need to store the following information: Each film is stored as an object of class Film and this class contains the variables needed to hold the preceding information. The data members in this class (as well as all of the other classes you will define) should be declared as private.

The database of films will be stored as an object of class FilmDB, containing an array of Film objects together with a count of how many films are currently entered in the database. The count variable indicates the number of films that have been entered; initially the array is created to have a certain capacity for film objects: the capacity is the length of the array of Film objects. But initially every slot in the array is null, that is, the empty Film object. At this point, the count is 0. Each time the user enters a new film, one of these null objects is then replaced with the user's data and count is incremented. Each new film is inserted into the array in such a way that the films remain alphabetically sorted by title. New entries are only inserted as long as there is still some capacity (some null objects) remaining.

Each Film object contains within it a Director object. Each object of the Director class has



Analagous to the FilmDB, the DirectorDB class organizes the Director objects into an array that is alphabetically sorted according to last name (first names break ties). This array is also preallocated and contains a corresponding count variable.

By definition, these four classes are deeply entwined: a FilmDB contains Films, which contain Directors, which in turn contain their own FilmDBs. While this may sound complicated, it requires no special work on your part. Simply define each class as you always have: specifying variable and methods names and types as needed. The entwined nature of this assignment's classes are summarized in the following diagram:

class structure

The defintitions of each class should be included together along with the CS5App class in the CS5App.java file. For this problem, submit your CS5App.java file under Homework 14, Problem 1.



The Film Class






The Director Class







The FilmDB Class






The DirectorDB Class







The CS5App Class




The main method drives the rest of the program and runs the user interface. This interface is similar in structure to those you have built in previous assignments.

The main method should begin with the lines

     F = new Film[100];     // creates a 100-film database by default
     D = new Director[100]; // creates a 100-director database by default
Then, it should present the user with the above menu of options and handle the option entered.

The handling of choices 0 through 6 are straightforward. The user is first prompted for an appropriate search value (options 0 and 1 don't even need a search value...). The appropriate method is called from either database F or D to print the desired information. Here are some details:





Helpful String Methods

The following Java-provided String methods will be useful in performing the String-based searches required in this assignment

Here are some examples of how each of these methods can be used:

String s = "Hamburger";
String t = "Urge";


+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

s.indexOf(t) -- returns the location of t within s or -1 if not there
if (s.indexOf(t) >= 0) H.out.println("s contains t"); else H.out.println("s does not contain t");
In this case, because "Urge" is capitalized, s.indexOf(t) would be -1 and the latter meddage would be printed out.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

s.toLowerCase() -- returns a string identical to s, but all lower case
if (s.toLowerCase().indexOf(t.toLowerCase())) H.out.println("s contains t (ignoring case)"); else H.out.println("s does not contain t (ignoring case)");
In this case, the former message would get printed.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

s.compareTo(t) -- returns 0 if s and t are identical strings returns a number less than 0 if s is before t alphabetically returns a number greater than 0 if s is after t alphabetically
if (s.compareTo(t) < 0) H.out.println("s is before t alphabetically"); else if (s.compareTo(t) > 0) H.out.println("s is after t alphabetically"); else H.out.println("s and t are identical strings");
In this case, the first message would be printed out.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

s.compareToIgnoreCase(t) -- returns 0 if s and t are identical strings returns a number less than 0 if s is before t (ignoring case) returns a number greater than 0 if s is after t (ignoring case)
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-



Extra Credit    Extra credit on this assignment involves replacing the methods that use for loops with ones that use recursion! We will look at a couple of these in class, and the same idea can be applied to the other methods that contain for loops... . Keep in mind that you don't have to use recursion at all -- this is simply if you'd like to try.


A Sample Run

The following text shows the output from a run of the program. Note that not every possible test is run here -- be sure to try out each option in your database!

Welcome the the CS 5 Movie Database.


There are 0 films in our database (max: 100)


Please choose from the following list:

   0 Display all directors
   1 Display all films
   2 Display all films by Title
   3 Display films by Director
   4 Display films by Year
   5 Display films by Rating (G, PG, ...)
   6 Display films by Review (0-10)
   7 Add a new film

   8 Save database to file
   9 Read database from file

  42 Quit

Which would you like? 9

Enter a file name: twofilms
Loading database contents from file ../twofilms.txt
100
2
Enter the title:                  Lord of the Rings: Return of
Enter the director's last name:   Jackson
Enter the director's first name:  Peter
Enter the movie's year:           2003
Enter the movie's MPAA rating:    PG-13
Enter a review score:             9.0


Enter the title:                  Gigli
Enter the director's last name:   Brest
Enter the director's first name:  Martin
Enter the movie's year:           2003
Enter the movie's MPAA rating:    R
Enter a review score:             2.2





There are 2 films in our database (max: 100)


Please choose from the following list:

   0 Display all directors
   1 Display all films
   2 Display all films by Title
   3 Display films by Director
   4 Display films by Year
   5 Display films by Rating (G, PG, ...)
   6 Display films by Review (0-10)
   7 Add a new film

   8 Save database to file
   9 Read database from file

  42 Quit

Which would you like? 0

Director #0 is Brest, Martin
Director #1 is Jackson, Peter



There are 2 films in our database (max: 100)


Please choose from the following list:

   0 Display all directors
   1 Display all films
   2 Display all films by Title
   3 Display films by Director
   4 Display films by Year
   5 Display films by Rating (G, PG, ...)
   6 Display films by Review (0-10)
   7 Add a new film

   8 Save database to file
   9 Read database from file

  42 Quit

Which would you like? 7

Enter the title:                  King Kong
Enter the director's last name:   Jackson
Enter the director's first name:  Peter
Enter the movie's year:           2005
Enter the movie's MPAA rating:    PG-13
Enter a review score:             6.0





There are 3 films in our database (max: 100)


Please choose from the following list:

   0 Display all directors
   1 Display all films
   2 Display all films by Title
   3 Display films by Director
   4 Display films by Year
   5 Display films by Rating (G, PG, ...)
   6 Display films by Review (0-10)
   7 Add a new film

   8 Save database to file
   9 Read database from file

  42 Quit

Which would you like? 1




Title:    Gigli
Director: Brest, Martin
Year:     2003
Rating:   R
Review:   2.2





Title:    King Kong
Director: Jackson, Peter
Year:     2005
Rating:   PG-13
Review:   6.0





Title:    Lord of the Rings: Return of the King
Director: Jackson, Peter
Year:     2003
Rating:   PG-13
Review:   9.0





There are 3 films in our database (max: 100)


Please choose from the following list:

   0 Display all directors
   1 Display all films
   2 Display all films by Title
   3 Display films by Director
   4 Display films by Year
   5 Display films by Rating (G, PG, ...)
   6 Display films by Review (0-10)
   7 Add a new film

   8 Save database to file
   9 Read database from file

  42 Quit

Which would you like? 2

Enter a titlepiece: king



Title:    King Kong
Director: Jackson, Peter
Year:     2005
Rating:   PG-13
Review:   6.0





Title:    Lord of the Rings: Return of the King
Director: Jackson, Peter
Year:     2003
Rating:   PG-13
Review:   9.0





There are 3 films in our database (max: 100)


Please choose from the following list:

   0 Display all directors
   1 Display all films
   2 Display all films by Title
   3 Display films by Director
   4 Display films by Year
   5 Display films by Rating (G, PG, ...)
   6 Display films by Review (0-10)
   7 Add a new film

   8 Save database to file
   9 Read database from file

  42 Quit

Which would you like? 3

Enter last name: Brest
Enter first name: Martin



Title:    Gigli
Director: Brest, Martin
Year:     2003
Rating:   R
Review:   2.2





There are 3 films in our database (max: 100)


Please choose from the following list:

   0 Display all directors
   1 Display all films
   2 Display all films by Title
   3 Display films by Director
   4 Display films by Year
   5 Display films by Rating (G, PG, ...)
   6 Display films by Review (0-10)
   7 Add a new film

   8 Save database to file
   9 Read database from file

  42 Quit

Which would you like? 8

Enter a file name: threefilms
Saving the database's contents to the file ../threefilms.txt



There are 3 films in our database (max: 100)


Please choose from the following list:

   0 Display all directors
   1 Display all films
   2 Display all films by Title
   3 Display films by Director
   4 Display films by Year
   5 Display films by Rating (G, PG, ...)
   6 Display films by Review (0-10)
   7 Add a new film

   8 Save database to file
   9 Read database from file

  42 Quit

Which would you like? 5

Enter a rating: 8.5



There are 3 films in our database (max: 100)


Please choose from the following list:

   0 Display all directors
   1 Display all films
   2 Display all films by Title
   3 Display films by Director
   4 Display films by Year
   5 Display films by Rating (G, PG, ...)
   6 Display films by Review (0-10)
   7 Add a new film

   8 Save database to file
   9 Read database from file

  42 Quit

Which would you like? 42



Until next time, the gallery is closed.