peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
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:
import chn.util.*;
import apcslib.*;
public class Movie implements Comparable
{
private String myTitle; // title of Bond film
private String myBondActor; // name of actor of portrayed James Bond
private int myYear; // year film was released
private double myFilmRating;// from all-reviews.com
private int myLengthHours; // hours (truncated) portion of film length
private int myLengthMinutes;// minutes beyond truncated hours
public Movie (String title, String name, int yr, double rating, int hrs, int min)
{
myTitle = title;
myBondActor = name;
myYear = yr;
myFilmRating = rating;
myLengthHours = hrs;
myLengthMinutes = min;
}
public String getTitle()
{
return myTitle;
}
public String getBondActor()
{
return myBondActor;
}
public int getYearFilmReleased()
{
return myYear;
}
public double getFilmRating()
{
return myFilmRating;
}
public int getFilmHrs()
{
return myLengthHours;
}
public int getFilmMin()
{
return myLengthMinutes;
}
public int compareTo(Object other)
{
return (int)(myFilmRating*10) - (int)((((Movie)other).myFilmRating)*10);
}
public String toString()
{
return (Format.left(myTitle,34) + Format.left(myBondActor,16)
+ Format.center(myYear,6) + Format.center(myFilmRating,7,1)
+ " " + myLengthHours + " hr " + myLengthMinutes + " min");
}
}
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...
import chn.util.*;
import apcslib.*;
public class Collection
{
private Movie[] movieList;
public Collection(String fileName = "../TMJamesBond.java/movies.txt")
loadData(fileName = "../TMJamesBond.java/movies.txt");
}
private void loadData(String fileName = "../TMJamesBond.java/movies.txt")
{
String movieTitle;
String bondName;
int yearReleased;
double movieRating;
int lengthHours;
int lengthMinutes;
FileInput inFile = new FileInput();
int numReleases = inFile.readInt();
movieList = new Movie[numReleases];
for (int i = 0; i < numReleases; i++)
{
movieTitle = inFile.readLine();
bondName = inFile.readLine();
yearReleased = inFile.readInt();
movieRating = inFile.readDouble();
lengthHours = inFile.readInt();
lengthMinutes = inFile.readInt();
movieList[i] = new Movie(movieTitle, bondName, yearReleased,
movieRating, lengthHours, lengthMinutes);
}
}
public void displayInfo()
{
System.out.print(Format.center("Film Title",34));
System.out.print(Format.center("Bond Actor",16));
System.out.print(Format.center("Year",6));
System.out.print(Format.center("Rating",7));
System.out.print(Format.right("Film Length",16));
System.out.println();
System.out.println();
for (int i = movieList.length - 1; i >= 0 ; i--)
{
String output = movieList[i].toString();
System.out.println(output);
}
}
public void Sort()
{
selectionSort(movieList);
}
/**
* Sorts Student objects in an array
* index using a selectionSort algorithm.
*
* @param list an array of type Student
*/
void selectionSort (Movie[ ] List)
{
int min;
for (int outer = 0; outer < List.length - 1; outer++)
{
min = outer;
for (int inner = outer + 1; inner < List.length; inner++)
{
if (List[inner].compareTo(List[min]) < 0)
{
min = inner; // a new smallest item is found
}
}
//swap list [outer] & list [flag]
Movie temp = List [outer];
List[outer] = List [min];
List [min] = temp;
}
}
public static void main(String[] args)
{
Collection seriesData = new Collection("../TMJamesBond.java/movies.txt");
seriesData.Sort();
seriesData.displayInfo();
}
}
I get ") missing" on the line
I get an error with a ')' expected for the Collection class on
loadData(fileName = "../TMJamesBond.java/movies.txt");
and I don't know why.
Any help appreciated...
public class Collection
{
private Movie[] movieList;
public Collection(){
loadData("../TMJamesBond.java/movies.txt");
}
private void loadData(String fileName)
{
// 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....