// input: // 1 9.1 243153 The Godfather (1972) // // output: // Search word? part // Rank Votes Rating Title // 2 139085 9.0 The Godfather: Part II (1974) // 40 129172 8.5 The Departed (2006) // 95 20401 8.2 The Apartment (1960) // 192 30587 8.0 Spartacus (1960) import java.io.*; import java.util.*; public class IMDBSearcherv1 { public static void main(String[] args) throws FileNotFoundException { System.out.println("This program will allow you to search the"); System.out.println("imdb top 250 movies for a particular phrase."); System.out.println(); Scanner console = new Scanner(System.in); System.out.print("Search word: "); String searchWord = console.next(); // NOTE: the heading is printed every time but shouldn't be // for a search word that results in no matches System.out.println("Rank Votes Rating Title"); Scanner fileScan = new Scanner(new File("imdb.txt")); while (fileScan.hasNextLine()) { String dataLine = fileScan.nextLine(); String dataLineLC = dataLine.toLowerCase(); if (dataLineLC.contains(searchWord.toLowerCase())) { printMovie(dataLine); } } } // Formats a movie's data for output. // Note: we need to use a Scanner for the line because the output // has data in a different order than the input public static void printMovie(String dataLine) { Scanner lineScan = new Scanner(dataLine); int ranking = lineScan.nextInt(); double rating = lineScan.nextDouble(); int votes = lineScan.nextInt(); String title = ""; while (lineScan.hasNext()) { title += lineScan.next() + " "; } System.out.println(ranking + "\t" + votes + "\t" + rating + "\t" + title); } }