java - Searching and sorting through an Arraylist -
i new java programmer , working on project requires me read text file has movie reviews.
once i've read file, asked search , sort through array of movies , return total number of reviews each movie average rate each movie.
the portion stuck on iterating through array list.
i using inner , outer loop , seem getting infinite loop.
i appreciate second set of eyes. have been staring @ project few days , starting not see mistakes.
here code:
import java.io.*; import java.util.*; import java.lang.*; public class moviereviewapp { public static void main(string[] args) { string strline = ""; string[] result = null; final string delimit = "\\s+\\|\\s+"; string title =""; //int rating = (integer.valueof(- 1)); arraylist<moviereview> movies = new arraylist<moviereview>(); //arraylist<string> titles = new arraylist<string>(); //arraylist<integer> ratings = new arraylist<integer>(); //hashmap<string, integer> hm = new hashmap<string, integer>(); //listmultimap<string, integer> hm = arraylistmultimap.create(); try { bufferedreader f = new bufferedreader(new filereader("/users/deborahjaffe/desktop/java/midterm/moviereviewdata.txt")); while(true) { strline = f.readline(); // reads line line of text file if(strline == null) { break; } result = strline.split(delimit, 2); //creates 2 strings //hm.put(result[0], new integer [] {integer.valueof(result[1])}); //hm.put(result[0], integer.valueof(result[1])); // titles.add(result[0]); //ratings.add(integer.valueof(result[1])); moviereview m = new moviereview(result[0]); movies.add(m); moviereview m2 = new moviereview(); int rating = integer.valueof(result[1]); int sz = movies.size(); (int = 0; < sz; i++) { (int j = 0; j < sz; j++) { m2 = movies.get(i); if (movies.contains(m2)) { m2.addrating(rating); } else { movies.add(m2); m2.addrating(rating); } } } movies.tostring(); //collections.sort(movies); } //end while f.close(); //set<string> keys = hm.keyset(); //collection<integer> values = hm.values(); } //end of try catch(filenotfoundexception e) { system.out.println("error: file not found"); } catch(ioexception e) { system.out.println("error opening file."); } } // end main } // end class
read file first , iterate through list or map searching, sorting etc. in above code, close while loop before iterating through list.
Comments
Post a Comment