943,815 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1033
  • Java RSS
Jan 14th, 2009
0

James Bond Search Program

Expand Post »
I was given a movie list, and I was asked to make a program to retrieve information from it and eventually modify the program to find certain movies. Right now I have a Collection class and a Movie class. The Movie class look like this:
Java Syntax (Toggle Plain Text)
  1. import chn.util.*;
  2. import apcslib.*;
  3.  
  4. public class Movie implements Comparable
  5. {
  6. private String myTitle; // title of Bond film
  7. private String myBondActor; // name of actor of portrayed James Bond
  8. private int myYear; // year film was released
  9. private double myFilmRating;// from all-reviews.com
  10. private int myLengthHours; // hours (truncated) portion of film length
  11. private int myLengthMinutes;// minutes beyond truncated hours
  12.  
  13. public Movie (String title, String name, int yr, double rating, int hrs, int min)
  14. {
  15. myTitle = title;
  16. myBondActor = name;
  17. myYear = yr;
  18. myFilmRating = rating;
  19. myLengthHours = hrs;
  20. myLengthMinutes = min;
  21. }
  22.  
  23. public String getTitle()
  24. {
  25. return myTitle;
  26. }
  27.  
  28. public String getBondActor()
  29. {
  30. return myBondActor;
  31. }
  32.  
  33. public int getYearFilmReleased()
  34. {
  35. return myYear;
  36. }
  37.  
  38. public double getFilmRating()
  39. {
  40. return myFilmRating;
  41. }
  42.  
  43. public int getFilmHrs()
  44. {
  45. return myLengthHours;
  46. }
  47.  
  48. public int getFilmMin()
  49. {
  50. return myLengthMinutes;
  51. }
  52.  
  53. public int compareTo(Object other)
  54. {
  55. return (int)(myFilmRating*10) - (int)((((Movie)other).myFilmRating)*10);
  56. }
  57.  
  58. public String toString()
  59. {
  60. return (Format.left(myTitle,34) + Format.left(myBondActor,16)
  61. + Format.center(myYear,6) + Format.center(myFilmRating,7,1)
  62. + " " + myLengthHours + " hr " + myLengthMinutes + " min");
  63. }
  64. }

The Collection class is the one I'm having difficulty with retrieving the file. I have it in the file with the program and it's all directed correctly to my understanding...

Java Syntax (Toggle Plain Text)
  1. import chn.util.*;
  2. import apcslib.*;
  3.  
  4. public class Collection
  5. {
  6. private Movie[] movieList;
  7.  
  8. public Collection(String fileName = "../TMJamesBond.java/movies.txt")
  9.  
  10. loadData(fileName = "../TMJamesBond.java/movies.txt");
  11. }
  12.  
  13. private void loadData(String fileName = "../TMJamesBond.java/movies.txt")
  14. {
  15. String movieTitle;
  16. String bondName;
  17. int yearReleased;
  18. double movieRating;
  19. int lengthHours;
  20. int lengthMinutes;
  21.  
  22. FileInput inFile = new FileInput();
  23.  
  24. int numReleases = inFile.readInt();
  25. movieList = new Movie[numReleases];
  26.  
  27. for (int i = 0; i < numReleases; i++)
  28. {
  29. movieTitle = inFile.readLine();
  30. bondName = inFile.readLine();
  31. yearReleased = inFile.readInt();
  32. movieRating = inFile.readDouble();
  33. lengthHours = inFile.readInt();
  34. lengthMinutes = inFile.readInt();
  35.  
  36. movieList[i] = new Movie(movieTitle, bondName, yearReleased,
  37. movieRating, lengthHours, lengthMinutes);
  38. }
  39. }
  40. public void displayInfo()
  41. {
  42. System.out.print(Format.center("Film Title",34));
  43. System.out.print(Format.center("Bond Actor",16));
  44. System.out.print(Format.center("Year",6));
  45. System.out.print(Format.center("Rating",7));
  46. System.out.print(Format.right("Film Length",16));
  47. System.out.println();
  48. System.out.println();
  49. for (int i = movieList.length - 1; i >= 0 ; i--)
  50. {
  51. String output = movieList[i].toString();
  52. System.out.println(output);
  53. }
  54. }
  55.  
  56. public void Sort()
  57. {
  58. selectionSort(movieList);
  59. }
  60. /**
  61.   * Sorts Student objects in an array
  62.   * index using a selectionSort algorithm.
  63.   *
  64.   * @param list an array of type Student
  65.   */
  66. void selectionSort (Movie[ ] List)
  67. {
  68. int min;
  69. for (int outer = 0; outer < List.length - 1; outer++)
  70. {
  71. min = outer;
  72. for (int inner = outer + 1; inner < List.length; inner++)
  73. {
  74. if (List[inner].compareTo(List[min]) < 0)
  75. {
  76. min = inner; // a new smallest item is found
  77. }
  78. }
  79. //swap list [outer] & list [flag]
  80. Movie temp = List [outer];
  81. List[outer] = List [min];
  82. List [min] = temp;
  83. }
  84. }
  85.  
  86. public static void main(String[] args)
  87. {
  88. Collection seriesData = new Collection("../TMJamesBond.java/movies.txt");
  89. seriesData.Sort();
  90. seriesData.displayInfo();
  91. }
  92.  
  93. }

I get ") missing" on the line
I get an error with a ')' expected for the Collection class on
Java Syntax (Toggle Plain Text)
  1. loadData(fileName = "../TMJamesBond.java/movies.txt");
and I don't know why.

Any help appreciated...
Similar Threads
Reputation Points: -1
Solved Threads: 0
Light Poster
IMtheBESTatJAVA is offline Offline
36 posts
since Oct 2008
Jan 14th, 2009
0

Re: James Bond Search Program

Java Syntax (Toggle Plain Text)
  1. public class Collection
  2. {
  3. private Movie[] movieList;
  4.  
  5. public Collection(){
  6.  
  7. loadData("../TMJamesBond.java/movies.txt");
  8. }
  9.  
  10. private void loadData(String fileName)
  11. {
  12. // REST OF THE CODE
You seriously misunderstand the way how to defining method and passing parameters from "caller" method to "worker" method.
Have look at Classes and Objects tutorial and take special care to read Defining Methods chapter

PS: Program still has lot of errors....
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 873
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Extending java.nio.ByteBuffer
Next Thread in Java Forum Timeline: Is it possible to create such a web based Instant Message System?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC