/* This program implements a search through a movie database. The program sets up a database of movie titles; It asks the user to type in a word and prints out all movies that contain that word. Laura Toma csci107 */ public class MovieSearch { public static void main (String args[]) { //setting up the variable that reads from user ReadStream r = new ReadStream(); //the movie database String[] movieDB = { "The fellowship of the ring", "Return of the king", "The hobbit", "Hotel Rwanda" }; //print a welcome message System.out.println(); System.out.println("Welcome to movie search!"); System.out.println("You have " + movieDB.length + " movies in the database."); //ask the user for a title or word to search String queryTitle; System.out.print("Enter a title or word: "); queryTitle = r.readString(); r.readLine(); //search through the database and print all matching movies System.out.println(); System.out.println("The following movies match:" ); int i = 0; int p; //the position where query matches String titleLowerCase; int count = 0; while (i < movieDB.length) { titleLowerCase = movieDB[i].toLowerCase(); p = titleLowerCase.indexOf(queryTitle); if (p != -1) { count++; //queryTitle is contained in movieDB[i]) System.out.println(" " + count + ". " + movieDB[i]); } i++; } System.out.println("Total " + count + " times."); } // end of main } // end of class