Can any one please help me out Over view

[b][red]This message was edited by azfariqbal at 2002-10-22 20:1:25[/red][/b][hr]
[b][red]This message was edited by azfariqbal at 2002-10-22 11:0:7[/red][/b][hr]
**********************************************************************
THE RATING FILE GIVING AT THE END I CREATED SEARCH CLASS ALREADY
Overview:
The application program reads in a few hundreds of movie ratings from an input file ("rating_list.txt"), and prints out the average rating for each movie. Each line in the input file represents one review, which indicates the title of the movie and the rating separated by "|".
Liar Liar | 5
Silence of the Lambs, The | 5
Star Wars | 3
Apollo 13 | 4
Silence of the Lambs, The | 5
Star Wars | 5
Men in Black | 2
Dead Man Walking | 5
Titanic | 5
Men in Black | 4
...
Ratings of a given movie should be stored in an object of a class called Mreview (defined in "Mreview.java.txt"; partially filled). This class has 2 fields: title and ratings:
public class Mreview implements Comparable
{
public Mreview(String ttl)
{
title = ttl;
ratings = new ArrayList();
}
...

// fields
private String title; // title of the movie
private ArrayList ratings; // array or ratings (as Integer's)
}
In the application program, Mreview objects are stored in an BST. So the element of each node is a (reference to a) Mreview object.
The order of the Mreview objects are based on the alphabetical order of the titles. So for instance, a Mreview for "Apollo 13" is found somewhere in the left subtree of a Mreview for "Liar Liar".
Toward the end of the program, you call toArrayInorder in the BST object to collect the Mreview objects. This will give you an array containing Mreview's which are alphabetically sorted by their titles.
Finally, the program prints out the average rating and the number of ratings for each movie, as follows:
Apollo 13 27 3.740740740740741
Dead Man Walking 31 4.064516129032258
Empire Strikes Back, The 37 4.135135135135135
Full Monty, The 61 4.016393442622951
Liar Liar 87 3.3448275862068964
Men in Black 45 3.511111111111111
Pulp Fiction 46 3.9347826086956523
Silence of the Lambs, The 40 4.1
Star Trek: First Contact 43 3.8372093023255816
Star Wars 88 4.318181818181818
Titanic 72 4.208333333333333
Toy Story 60 4.0

--------------------------------------------------------------------------------

Some Specifics:
You need to write/complete 2 files for this assignment:

(1) "Mreview.java.txt"
Complete this file by adding some methods. You figure out which methods you need. Hints are:

compareTo. You DEFINITELY need this method. The specification is described above.
a method which receives a rating score (of type Integer) and inserts it in the ratings array.
a couple of public methods which return the (private) fields to outside.
NOTES: You can name the methods as you like. Also note the restriction on this file: you can add methods, but you must NOT modify anything in the file NOR add any field.

(2) An application file
Name the file as you like. You write from scratch. Some details and hints:

The program must read in each line from the input file and process it. You can look at the program on Weiss p. 23 for an example of file input.
After you get a line (by readLine()), you need to obtain the title and the rating score. You figure out how you can do this. There are several ways.
One way is to read from the line every word (a white-space-delimited string token/term) repeatedly until the end of the line, and build each part. You can use a StringTokenizer object to do this. Look at a program on Weiss p. 21 for an example. More example is below.
StringTokenizer tokenizer;
String wrd;

// ..Assume a String 'oneLine' is already a line from the input file
tokenizer = new StringTokenizer(oneLine);
while (tokenizer.hasMoreTokens())
{
wrd = tokenizer.nextToken();
...
For the title, you concatenate word strings from the first word until (and not including) "|".
One way is to use the method substring in the Java String class.
For the rating score, you can use a static method valueOf defined in the Java Integer class in order to convert a String number to an Integer. For example,
String snum = "26";
Integer n = Integer.valueOf(snum); // n is an Integer 26
Now you look up the Mreview record for this title in the BST (which you have already created/added somewhere near the beginning of the code). To do so, you must first create a (new) Mreview object, and then use it to search the title in the tree.
If the title already exists in the tree, you simply add the rating score (an Integer object) in the ratings array in the Mreview object. I suggest you set up a method in Mreview class which does this (see (1) Mreview.java.txt b. above), and call it with the new rating.
Or if the title does not exist in the tree, you insert the new Mreview object.
You probably have to cast Mreview for the value/object returned from BST find.
After you processed all lines from the input file, you collect the Mreview objects in an ArrayList object by calling toArrayInorder in the BST tree. The Mreview objects are in the alphabetically sorted order by the titles.

When you print necessary information of each Mreview object to system.out, I suggest you get the title and the ratings array separately, instead of making this task as toString.

To get the title and ratings array, you must set up methods in Mreview class (see (1) Mreview.java.txt c. above).
To obtain the average rating, you must convert each Integer in the ratings array to a primitive int. You can do this by calling a method intValue defined in the Java Integer class. For example,
Integer n1 = new Integer(3);
int num = n1.intValue() * 2;
You probably have to cast Integer for the object retrieved from the ratings array.
As for the output, I'm not particular about the format, as long as you display 2 information (title and average rating) for a movie in one line. If you like to "format" the title part in a fixed size column as shown earlier in this document, feel free to use my method below.
public static String makeNstring(String s, int len)
{
int slen = s.length();
String ret;
if (slen == len)
ret = s;
else if (slen > len)
ret = s.substring(0, len);
else
{
String padding = "";
int toGo = len - slen;
for (int i = 0; i < toGo; i++)
padding += " ";
ret = s + padding;
}
return ret;
}


************************************************************************

//////// RATING FILE /////////////
wehaveto read out this file

Liar Liar | 5
Silence of the Lambs, The | 5
Star Wars | 3
Apollo 13 | 4
Silence of the Lambs, The | 5
Star Wars | 5
Men in Black | 2
Dead Man Walking | 5
Titanic | 5
Men in Black | 4
Liar Liar | 2
Star Wars | 5
Star Wars | 5
Liar Liar | 5
Toy Story | 4
Silence of the Lambs, The | 3
Silence of the Lambs, The | 5
Star Wars | 5
Liar Liar | 3
Empire Strikes Back, The | 4
Pulp Fiction | 5
Silence of the Lambs, The | 4
Silence of the Lambs, The | 3
Full Monty, The | 4
Star Trek: First Contact | 3
Toy Story | 4
Dead Man Walking | 3
Titanic | 2
Empire Strikes Back, The | 3
Star Trek: First Contact | 2
Empire Strikes Back, The | 4
Star Trek: First Contact | 4
Men in Black | 4
Silence of the Lambs, The | 5
Silence of the Lambs, The | 4
Liar Liar | 3
Titanic | 5
Full Monty, The | 3
Pulp Fiction | 5
Star Trek: First Contact | 3
Titanic | 4
Apollo 13 | 4
Silence of the Lambs, The | 4
Titanic | 3
Liar Liar | 4
Titanic | 5
Dead Man Walking | 4
Men in Black | 3
Titanic | 4
Pulp Fiction | 4

and so on there are hundreds of ratings






Comments

  • I think the text is too long that
    people will get lost on the way.

    This is the same message you posted
    previously. And if I understood correctly
    Chamster asked if you need code to start, but
    you did not answer. I suggest you should
    accept chamster's offer and continue from there.
    This shouldn't be a difficult task.
    Any way if Iam wrong let me know !

    bashiro
  • : I think the text is too long that
    : people will get lost on the way.
    :
    : This is the same message you posted
    : previously. And if I understood correctly
    : Chamster asked if you need code to start, but
    : you did not answer. I suggest you should
    : accept chamster's offer and continue from there.
    : This shouldn't be a difficult task.
    : Any way if Iam wrong let me know !
    :
    : bashiro
    :
    Hi
    yes I need a code to start can u please help me out

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories