Movie.java and MovieDatabase.java.
String title: title of the movie.String[] directors : director(s) of the movie.String[] casts: actors and actresses of the movie.int year: the year that the movie released.Movie(String title, String[] directors, String[] casts, int year): don't use shallow copying for the arrays. boolean searchTitle(String keyword): search if the title contains the keyword. boolean searchDirectors(String keyword): returns true if one of the director names contains the keyword.boolean searchCasts(String keyword): returns true if one of the casts name contains the keywordboolean search(Sring keyword) : returns true if either title, director names or cast names contain the keyword.searchTitle("MATRIX") is same as searchTitle("Matrix")searchTitle("trix") should return true because the word Matrix
contains trix. void showInfo(): show the information of the movie at the Dos Prompt. The format is like this
Title: The Matrix Directors: Andy Wachowski, Larry Wachowski Casts: Keanu Reeves, Laurence Fishburne, Carrie-Anne Moss, Hugo Weaving Year: 1999
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();
}
}
|
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 |
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"));
}
}
|
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(): construct an empty database. void add(Movie movie): add a movie to the database, ignore it if there are more than 1000 movies. void search(String keyword): search the keyword in all the movies in the database. If a movie contains the keyword,
prints out the information at the Dos Prompt. See the sample output for the format.void showAll() : prints out all the movies at the Dos prompt. See the sample output for the format.
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");
}
}
|
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 |
String class, toLowerCase(), toUpperCase() return lower case (or upper case) or the String.
Please refer to this link
and this link.String class, indexOf(String str)
returns the index within this string of the first occurrence of the specified substring, it returns -1 if str is not found.
You should use the method in all the search methods.
Please refer to this link. /** Name: Charles Li * Student ID : 000 000 000 * PIC ID: ccli * E-mail: ccli@math.ucla.edu * Discussion: 1A * Assignment: hw1 * * I, Charles Li, pledge that this is my own independent work, which * conforms to the guidelines of academic honesty as described in the course * syllabus. * */