All pastes #283062 Raw Edit

/19/movie/MovieTest

public java v1 · immutable
#283062 ·published 2006-12-18 01:52 UTC
rendered paste body
// Jim Herreroimport java.io.*;import java.util.*;public class MovieTest {  public static void main() throws IOException  {    Scanner sc = new Scanner(new File("movies.txt"));    ArrayList<Movie> movies = new ArrayList<Movie>();    int year;    String line, title;    String[] names;    LinkedList<Person> actors;    Person director;    while(sc.hasNext())    {      line = sc.nextLine();      year = Integer.valueOf(line.substring(0, 4));      title = line.substring(5, 36); //trim?      names = line.substring(38, 84).split(", "); //trim?      actors = new LinkedList<Person>();      for(String actor : names)        actors.add(new Person(actor.substring(0, actor.indexOf(" ")),                   actor.substring(actor.indexOf(" ") + 1)));      names = line.substring(89).split(" "); //trim?      director = new Person(names[0], names[1]);      movies.add(new Movie(year, title, director, actors));    }    Collections.sort(movies);    int numActors = 0;    for(Movie thismovie : movies)    {      System.out.println(thismovie);      for(Person thisactor : thismovie.getActors())        numActors++;    }    System.out.println(numActors + " actors total");  }}