import java.io.*; import java.util.*; import java.util.StringTokenizer; class read { public static void main(String[]args) { populateFilmVector(); bestfilm(); } static void populateFilmVector(){ String movie; Vector filmList = new Vector(); try { File data = new File("input.txt"); FileReader fr = new FileReader(data); BufferedReader in = new BufferedReader(fr); movie = in.readLine();//read first line while(movie!=null) { StringTokenizer tokens = new StringTokenizer(movie,","); String title = tokens.nextToken(); String lead = tokens.nextToken(); String runTime = tokens.nextToken(); String rating = tokens.nextToken(); String id = tokens.nextToken(); filmTest f = new filmTest(title,lead,runTime,Double.parseDouble(rating),id); filmList.add((Object)f); movie = in.readLine(); } in.close(); } catch(IOException e) { System.out.print("Non-Existant File"); } for(int i=0;i<filmList.size();i++) { filmTest f = (filmTest)filmList.get(i); f.displayDetails(); } } static void bestfilm() { } }
//example using Vectors import java.util.*; class filmTest { String title; String lead; String runTime; double rating; String id; public filmTest(String n,String l,String r,double s,String i) { title=n; lead=l; runTime=r; rating=s; id=i; //bestfilm(rating); } public void displayDetails() { System.out.println("\nFilm title :" + title); System.out.println("Lead role :" + lead); System.out.println("Run time :" + runTime); System.out.println("Rating :" + rating); System.out.println("id :" + id); } /* public double bestfilm(double rating) { double max=5.0; if ( rating == max) { System.out.println("GJHJK"); } for ( int i = 1; i < rating; i++) { if ( rating > rating) { max = rating; } } return max;} { }*/ }//end class
they are my two java files i want to search thorugh film items and find the one with highest rating have been looking at it for ages with no look would appreciate any help thanks with how to approach or do it thanks
--- Update ---
Film title ain & Gain
Lead role wayne Jhonson
Run time :123
Rating :4.5
id :23415
Film title :2br/1ba
Lead role :Spencer Grammer
Run time :113
Rating :3.2
id :57324
Film title :Training Day
Lead role enzel Washington
Run time :136
Rating :5.0
id :23244
Film title :Lone Surivoe
Lead role :Mark Wahlberg
Run time :141
Rating :4.8
id :45355
Film title :Grown ups 2
Lead role :Adam Sandeler
Run time :98
Rating :4.2
id :13564
Press any key to continue . . .
that is my out put i want this to be out put along with which ever one has the highest rating