// Helene Martin, CSE 142 // Displays information about movies // matching the user's search query import java.util.*; import java.io.*; public class IMDB { 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 search = console.next().toLowerCase(); Scanner input = new Scanner(new File("imdb.txt")); /* find out if there's a first match if there is: heading as long as there's a match: print match print number of matches */ String line = find(search, input); int matches = 0; if (line.length() > 0) { System.out.println("Rank Votes Rating Title"); while (line.length() > 0) { matches++; printLine(line); line = find(search, input); } } System.out.println("Matches: " + matches); } // finds and returns a line matching search in input public static String find(String search, Scanner input) { while (input.hasNextLine()) { String line = input.nextLine(); String lineLC = line.toLowerCase(); if (lineLC.contains(search)) { return line; } } return ""; } // breaks up a movie line into its parts and prints // a formatted version public static void printLine(String line) { Scanner lineScan = new Scanner(line); int rank = lineScan.nextInt(); double score = lineScan.nextDouble(); int votes = lineScan.nextInt(); String title = ""; // lineScan.nextLine() while (lineScan.hasNext()) { title = title + lineScan.next() + " "; } System.out.println(rank + "\t" + votes + "\t" + score + "\t" + title); } }