// CSE 142, Summer 2008 (Marty Stepp) // // Displays IMDB's Top 250 movies that match the user's search string. import java.io.*; // File import java.util.*; // Scanner public class Movies { public static void main(String[] args) throws FileNotFoundException { Scanner console = new Scanner(System.in); System.out.print("Search word? "); String searchWord = console.next(); int matches = 0; Scanner input = new Scanner(new File("imdb.txt")); while (input.hasNextLine()) { String line = input.nextLine(); // "1 9.1 243153 The Godfather (1972)" Scanner lineScanner = new Scanner(line); int rank = lineScanner.nextInt(); double rating = lineScanner.nextDouble(); int votes = lineScanner.nextInt(); String title = lineScanner.nextLine(); // does title contain searchWord? if (title.toLowerCase().indexOf(searchWord.toLowerCase()) != -1) { // found a match! matches++; System.out.println(rank + "\t" + votes + "\t" + rating + "\t" + title); } } System.out.println(matches + " matches."); } }