/* The program sets up a database of movie titles. It then asks the user to type in a keyword and prints out all movies that contain that keyword. Charlie Ash csci 101 */ public class MyImdb { public static void main (String args[]) { // setting up the variable that reads from user ReadStream r = new ReadStream(); // the movie database String[] movieDB = { "The Godfather: Part I", "The Godfather: Part II", "Wedding Crashers", "Anchorman", "Scarface", "Sin City", "Any Given Sunday", "Rounders", "The Chronicles of Narnia", "The Shawshank Redemption" }; // welcome message System.out.println("Welcome to Charlie's movie search!"); System.out.println("You have " + movieDB.length + " movies to choose from."); System.out.println("Please enter a keyword to search: "); // get keyword from user String search; search = r.readString(); r.readLine(); // declare variables int i=0; int found=0; //number of movies found // change the keyword to lower case String lowerCaseSearch = search.toLowerCase(); System.out.println("Movies containing your search: "); while (i < movieDB.length) { // change the movie to lower case String lowerCaseMovie = movieDB[i].toLowerCase(); int pos = lowerCaseMovie.indexOf(lowerCaseSearch); /* indexOf() will go through the entire title of each i-th movie (movieDB[i]) to find if the keyword (stored in variable "search") is anywhere in the text */ if (pos != -1) { System.out.println((found+1) + ". " + movieDB[i]); // print each movie found found++; } i++; //i = i+1; } if (found == 1) { System.out.println("Congratulations on finding 1 movie."); } else if (found > 1) { System.out.println("Congratulations on finding " + found + " movies."); } else System.out.println("There were no matches. Sorry."); } // end of main } // end of class