Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 33

Thread: Find Highest rated movie

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Find Highest rated movie

    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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Find Highest rated movie

    i want this to be out put along with which ever one has the highest rating
    Can you post a short example of what you want the output to look like?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Find Highest rated movie

    This is the desired output


    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

    Best film based on rating is

    Film title :Training Day
    Lead role enzel Washington
    Run time :136
    Rating :5.0
    id :23244


    Press any key to continue . . .

    i want to search through the vector and return the highest rated film
    Last edited by dubs4sam; April 17th, 2014 at 11:37 AM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Find Highest rated movie

    Is the difference the last 8 lines of the output?
    The details are in an object in the Vector. The code needs to find the index into the Vector that points to the object with the highest rating. After the others are printed, then print the heading and use the saved index to print the data for the one with the highest rating.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Find Highest rated movie

    ye

    could you give me some idea how to do that im looking at this for ages and not getting anywhere

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Find Highest rated movie

    One technique for search a list for a max value is to use a loop to compare the current max value against the next element from the list. If the next element is greater in value, save its index. To start the search set the index to 0 (the first element in the list). At the end of the loop, the saved index will be to the highest element in the list.
    The compare would be like this:
      theList[theMaxIndex] < theList[i]
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2014
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Find Highest rated movie

     for (int i = 0;i<filmList.size();i++)
     	{
     
     		filmList(5) = filmList(i);
     
    	}

    thats what iv done so far just wandering am i going in the right direction or is that wrong

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Find Highest rated movie

    Can you explain what the code in that loop is supposed to be doing?

    It looks like it assigns the values returned by a method to another method.
    There is no way to assign values to a method.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Mar 2014
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Find Highest rated movie

    i have it wrong what i want it to do is look at each element and see if its greater than the last to find my highest rating i am getting an error for my loop at the miniute

    //************** Error messaage ********************//


    C:\Users\Desktop\test\read.java:66: error: cannot find symbol
    filmList(5) = filmList(i);
    ^
    symbol: method filmList(int)
    location: class read
    C:\Users\Desktop\test\read.java:66: error: cannot find symbol
    filmList(5) = filmList(i);
    ^
    symbol: method filmList(int)
    location: class read

    2 errors

    Tool completed with exit code 1

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Find Highest rated movie

    The ()s are used with methods to surround the args being passed to the method.
    filmList is a variable of type Vector, not the name of an method.

    Look at the API doc for the Vector class and see what methods it has that will return the contents of the Vector at a specific location in the Vector. The code in post#1 looks like it uses the get method.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Mar 2014
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Find Highest rated movie

    cant get my head around it

    thanks for the help anyway

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Find Highest rated movie

    To access the contents of an Vector use a method like the get method used in post#1
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Mar 2014
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Find Highest rated movie

    Write a method called bestFilm() that searches through the FilmVector and returns the best film based on the ratings. The method should return the Film object

    thats exactally what im trying to do when i try to pass the peramiters needed to the other method i get the error that the item cant be found

     
    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);
    System.out.println(i);
    				f.displayDetails();
     
    		}
    bestfilm(filmlist);
     
    }
    static void bestfilm(filmlist)
    {
    for(int i=0;i<filmList.size();i++)
     
    		{
     
    			filmTest f = (filmTest)filmList.get(rating);
    System.out.println(i);
    				f.displayDetails();
     
    	}
    }
     
     
     
     
     
     
    }

    //*********************ERROR MESSAGE**************************\\

    C:\Users\Andrew\Desktop\test\read.java:58: error: <identifier> expected
    static void bestfilm(filmlist)
    ^
    1 error

    Tool completed with exit code 1

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Find Highest rated movie

    The code needs to be properly formatted so the alignment of the {s and }s can be seen.

    The error message sounds like the code is in the wrong place, maybe inside of another method. Hard to tell with the way the { and }s are positioned.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Mar 2014
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Find Highest rated movie

     
    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);
    				System.out.println(i);
    				f.displayDetails();
    		}
    bestfilm(filmlist);
    }
     
    static void bestfilm(List filmlist)
    		{
    			for(int i=0;i<filmList.size();i++)
    				{
    					filmTest f = (filmTest)filmList.get(rating);
    					System.out.println(i);
    					f.displayDetails();
    				}
    		}
    }

    i fixed the layou of the {'s still getting error still dont know ho i would do

    Write a method called bestFilm() that searches through the FilmVector and returns the best film based on the ratings. The method should return the Film object


    would it work if i passed the object f to the bestfilm method ?

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Find Highest rated movie

    i fixed the layou of the {'s
    It's still not right. For example there are }s in the first column in the middle of the code.
    The only place a } should be in the first column is at the end of a class's definition.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Mar 2014
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Find Highest rated movie

    Quote Originally Posted by Norm View Post
    It's still not right. For example there are }s in the first column in the middle of the code.
    The only place a } should be in the first column is at the end of a class's definition.
    That error only occurs when I attempt to pass down the list to the method I counted an even
    Number of }'s

    Is it even possible to find the highest rated film based on rating with the code I have ?
    Benn trying it for a while no and getting no where

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Find Highest rated movie

    Are all the compiler errors fixed? They need to be fixed before the code can be executed for testing.

    If there are errors, copy the full text of the error messages and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Mar 2014
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Find Highest rated movie

    //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;
     
       }
     
     
    public void displayDetails()
    	{
    		System.out.println("\nFilm title :" + title);
    		System.out.println("Lead role :" + lead);
    		System.out.println("Run time :" + runTime + " Mins");
    		System.out.println("Rating :" + rating);
    		System.out.println("id :" + id);
    }
    public void bestfilm()
    {
     
    }
     
     
     
     
     
     
     
     
    }//end class

    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);
    				System.out.println(i);
    				f.displayDetails();
    		}
     
    bestfilm(filmlist);
     
    }
     
    	static void bestfilm(List filmlist)
    		{
    			for(int i=0;i<filmList.size();i++)
    				{
    					filmTest f = (filmTest)filmList.get(rating);
    					System.out.println(i);
    					f.displayDetails();
    				}
    		}
    }

    //*****************************ERROR MESSAGE**********************************\\

    C:\Users\Desktop\test\read.java:55: error: cannot find symbol
    bestfilm(filmlist);
    ^
    symbol: variable filmlist
    location: class read
    C:\Users\Desktop\test\read.java:61: error: cannot find symbol
    for(int i=0;i<filmList.size();i++)
    ^
    symbol: variable filmList
    location: class read
    C:\Users\Desktop\test\read.java:63: error: cannot find symbol
    filmTest f = (filmTest)filmList.get(rating);
    ^
    symbol: variable rating
    location: class read
    C:\Users\Desktop\test\read.java:63: error: cannot find symbol
    filmTest f = (filmTest)filmList.get(rating);
    ^
    symbol: variable filmList
    location: class read
    Note: C:\Users\Desktop\test\read.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    4 errors

    Tool completed with exit code 1

    ************************************************** ************
    mY FIST BIT OF CODE "FILMtEST COMPILES alright its the second bit of code i put up that has the issue.

    what item from the code should i pass to the method bestfilm() in order to
    Write a method called bestFilm() that searches through the FilmVector and returns the best film based on the ratings. The method should return the Film object ?.
    is this possilbe with my code ?

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Find Highest rated movie

    what item from the code should i pass to the method bestfilm() in order to
    Write a method called bestFilm() that searches through the FilmVector
    If it is going to search the FilmVector, pass a reference to that.
    The method should return the Film object
    It could return the object or it could return the index to that object.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Mar 2014
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Find Highest rated movie

    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);
    bestfilm(filmList);
    		 	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);
    				System.out.println(i);
    				f.displayDetails();
    		}
     
     
     
    }
     
    	static void bestfilm(Vector filmList)
    {
     
         for(int i=0;i<filmList.size();i++)
     
    	 		{
     
     
    			}
     
    }
    }

    i have it compiling with the vector passed down
    is a for loop the best way to search through the FilmVector and return the best film based on the ratings.?

    i have a for loop started just wanst to sure what to write next

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Find Highest rated movie

    what to write next
    What are the steps that you have working now?
    What is the next step you are working on?
    What are the steps the bestfilm method should do?

    Why is the posted code so poorly formatted? It makes the code very to read and understand.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Junior Member
    Join Date
    Mar 2014
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Find Highest rated movie

    import java.io.*;
    import java.util.*;
    import java.util.StringTokenizer;
     
    class read
    {
    	public static void main(String[]args)
    	{
          populateFilmVector();
        }
     
    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);
    bestfilm(filmList);
    			 	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);
    				System.out.println(i);
    				f.displayDetails();
    		}
    }//end method
     
     
    static void bestfilm(Vector filmList)//best film method
    	{
    	     for(int i=0;i<filmList.size();i++)//search through vector
    	 		{
                                    //whatever to be done in for loop
     
    			}
    	}//end method
    }//end class

    The next step i am working on is comparing the rating of each of the films

    the best fiml method should compare the rating for each film and display the film with the best rating

    "method called bestFilm() that searches through the FilmVector and returns the best film based on the ratings."

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Find Highest rated movie

    comparing the rating of each of the films
    I don't see any code to do that. Where is the rating stored? The code needs to get each film's rating so it can compare it against the best found so far.

    returns the best film based on the ratings
    The definition needs to be changed so the method can return the file. Now it is defined as returning void which means it doesn't return anything.

    One problem I see is that the Vector that is filled with data is defined local to a method and will go away when the method exits. The method needs to return a reference to the Vector so that it can be passed to other methods as needed.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Junior Member
    Join Date
    Mar 2014
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Find Highest rated movie

    //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(s);
       }
     
     
    public void displayDetails()
    	{
    		System.out.println("\nFilm title :" + title);
    		System.out.println("Lead role :" + lead);
    		System.out.println("Run time :" + runTime + " Mins");
    		System.out.println("Rating :" + rating);
    		System.out.println("id :" + id);
    }
    public double bestfilm(double s)
    {
    	if(s >= s)
    	{
    		/*	System.out.println("Best film based on rating is ");
    			System.out.println("-----------------------------------------");
    			System.out.println("\nFilm title :" + title);
    			System.out.println("Lead role :" + lead);
    			System.out.println("Run time :" + runTime + " Mins");
    			System.out.println("Rating :" + rating);
    			System.out.println("id :" + id);
    			System.out.println("-----------------------------------------");*/
    	}
    	return s;
     
    //end class

    import java.io.*;
    import java.util.*;
    import java.util.StringTokenizer;
     
    class read
    {
    	public static void main(String[]args)
    	{
          populateFilmVector();
        }
     
    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);
    bestfilm(filmList);
    			 	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);
    				System.out.println(i);
    				f.displayDetails();
    		}
    }//end method
     
     
    static void bestfilm(Vector filmList)//best film method
    	{
    	     for(int i=0;i<filmList.size();i++)//search through vector
    	 		{
     
     
    			}
     
    	}//end method
    }//end class

    in the first bit of code ther im getting some where i think if i compare "s" to 5.0 it prints out the film with the 5.0 rating

    but is the a way to compare the "s" to the variable before it

    for example i want to do

        if(s >= s)
           {
              print "s" which would relate to the highest rated film
            }

Page 1 of 2 12 LastLast

Similar Threads

  1. Movie of BufferedImages
    By Ludicrous in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 26th, 2013, 07:09 PM
  2. Printing highest number of array. Can't find my error.
    By Praetorian in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 15th, 2013, 11:46 PM
  3. Top Java frameworks as rated by developers
    By pjagielski in forum The Cafe
    Replies: 0
    Last Post: August 15th, 2012, 12:05 PM
  4. Replies: 4
    Last Post: June 10th, 2009, 01:04 AM