James Bond Search Program

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2008
Posts: 37
Reputation: IMtheBESTatJAVA has a little shameless behaviour in the past 
Solved Threads: 0
IMtheBESTatJAVA IMtheBESTatJAVA is offline Offline
Light Poster

James Bond Search Program

 
0
  #1
Jan 14th, 2009
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:
  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...

  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
  1. loadData(fileName = "../TMJamesBond.java/movies.txt");
and I don't know why.

Any help appreciated...
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,197
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 486
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: James Bond Search Program

 
0
  #2
Jan 14th, 2009
  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....
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC