PIC20A

Homework 2: Movie Database

Assignment

You are going to write 2 classes Movie.java and MovieDatabase.java.

Movie.java

The class represents movies. It has 4 private members:
Member variables It has one public constructor:
Constructor It has several public methods:
Methods Here are some sample outputs
Test1.java
To make sure that you are not using shallow copy.
public class Test1 {
    public static void main(String[] args) {
        String[] directors = {"Andy Wachowski", "Larry Wachowski"};
        String[] casts =  {"Keanu Reeves", "Laurence Fishburne","Carrie-Anne Moss", "Hugo Weaving"};
        Movie movie = new Movie("The Matrix",  directors,  casts,1999);
        movie.showInfo();
        // change one name of the directors
        directors[1] = "Charles Li";
        movie.showInfo();
    }
}
Output
Title: The Matrix
Directors: Andy Wachowski, Larry Wachowski
Casts: Keanu Reeves, Laurence Fishburne, Carrie-Anne Moss, Hugo Weaving
Year: 1999
Title: The Matrix
Directors: Andy Wachowski, Larry Wachowski
Casts: Keanu Reeves, Laurence Fishburne, Carrie-Anne Moss, Hugo Weaving
Year: 1999

Test2.java
public class Test2 {
    public static void main(String[] args) {
        String[] directors = {"Andy Wachowski", "Larry Wachowski"};
        String[] casts =  {"Keanu Reeves", "Laurence Fishburne","Carrie-Anne Moss", "Hugo Weaving"};
        Movie movie = new Movie("The Matrix",  directors,  casts,1999);
        movie.showInfo();
        System.out.println("searchTitle(\"matrix\") : " + movie.searchTitle("matrix"));
        System.out.println("searchTitle(\"hello\") : " + movie.searchTitle("hello"));
        System.out.println("searchDirectors(\"Andy\") : " + movie.searchDirectors("Andy"));
        System.out.println("searchDirectors(\"Charles\") : " + movie.searchDirectors("Charles"));
        System.out.println("searchDirectors(\"chowsk\") : " + movie.searchDirectors("chowsk"));
        System.out.println("searchCasts(\"Charles\") : " + movie.searchCasts("Charles"));
        System.out.println("searchCasts(\"Hugo Weaving\") :  " + movie.searchCasts("Hugo Weaving"));
        System.out.println("searchCasts(\"reeves\") : " + movie.searchCasts("reeves"));
        System.out.println("search(\"MATRIX\") : " + movie.search("MATRIX"));
        System.out.println("serach(\"HELLO\") : " + movie.search("HELLO"));
    }
}
Output
Title: The Matrix
Directors: Andy Wachowski, Larry Wachowski
Casts: Keanu Reeves, Laurence Fishburne, Carrie-Anne Moss, Hugo Weaving
Year: 1999
searchTitle("matrix") : true
searchTitle("hello") : false
searchDirectors("Andy") : true
searchDirectors("Charles") : false
searchDirectors("chowsk") : true
searchCasts("Charles") : false
searchCasts("Hugo Weaving") :  true
searchCasts("reeves") : true
search("MATRIX") : true
serach("HELLO") : false

MovieDatabase.java

The class represents a database of movies. You can assume that there are no more than 1000 movies in the database. You can have as many private members as you like.
The class has the following public methods:
Constructor
Methods
Test3.java
public class Test3 {
    public static void main(String[] args) {
               String[] directors = {"Andy Wachowski", "Larry Wachowski"};
               String[] casts =  {"Keanu Reeves", "Laurence Fishburne","Carrie-Anne Moss", "Hugo Weaving"};
               Movie movie1 = new Movie("The Matrix",  directors,  casts,1999);
               Movie movie2 = new Movie("The Matrix Reloaded", directors, casts, 2003);
               String[] directors3 = {"Quentin Tarantino"};
               String[] casts3 = {"Uma Thurman", "David Carradine", "Lucy Liu"};
               Movie movie3 = new Movie("Kill Bill: Vol. 1", directors3, casts3, 2003);
               String[] directors4={"John Woo"};
               String[] casts4 = {"Ben Affleck", "Uma Thurman"};
               Movie movie4 = new Movie("Paycheck", directors4, casts4, 2003);
               MovieDatabase database = new MovieDatabase();
               database.add(movie1);
               database.add(movie2);
               database.add(movie3);
               database.add(movie4);
               database.showAll();
               System.out.println("Search for Thurman................. ");
               database.search("Thurman");
               System.out.println("Search for Matrix.................... ");
               database.search("Matrix");
    }
}
Output
Title: The Matrix
Directors: Andy Wachowski, Larry Wachowski
Casts: Keanu Reeves, Laurence Fishburne, Carrie-Anne Moss, Hugo Weaving
Year: 1999

Title: The Matrix Reloaded
Directors: Andy Wachowski, Larry Wachowski
Casts: Keanu Reeves, Laurence Fishburne, Carrie-Anne Moss, Hugo Weaving
Year: 2003

Title: Kill Bill: Vol. 1
Directors: Quentin Tarantino
Casts: Uma Thurman, David Carradine, Lucy Liu
Year: 2003

Title: Paycheck
Directors: John Woo
Casts: Ben Affleck, Uma Thurman
Year: 2003

Search for Thurman.................
Title: Kill Bill: Vol. 1
Directors: Quentin Tarantino
Casts: Uma Thurman, David Carradine, Lucy Liu
Year: 2003

Title: Paycheck
Directors: John Woo
Casts: Ben Affleck, Uma Thurman
Year: 2003

Search for Matrix....................
Title: The Matrix
Directors: Andy Wachowski, Larry Wachowski
Casts: Keanu Reeves, Laurence Fishburne, Carrie-Anne Moss, Hugo Weaving
Year: 1999

Title: The Matrix Reloaded
Directors: Andy Wachowski, Larry Wachowski
Casts: Keanu Reeves, Laurence Fishburne, Carrie-Anne Moss, Hugo Weaving
Year: 2003

Hints

What to submit

Call your source code file Movie.java, MovieDatabase.java. Put this file in your submit folder. Do not place this file inside another folder within your submit folder.

Remark

Solution

Movie.java, MovieDatabase.java.