Howdy, Stranger!

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

Categories

wordCount

azfariqbalazfariqbal Member Posts: 15
hi,
i ve' to write a program which read a 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
****************************************************

which contain name of movies and their rating "Liar Liar | 5" 5 is its rating. and so on.

i ve to calculate its rating average.
After i processed all lines from the input file, you collect the Mreview objects(file name) in an ArrayList object by calling toArrayInorder in the BST tree. The Mreview objects are in the alphabetically sorted order by the titles. so the output should in this form:

Apollo 13 27 3.740740740740741 //27 is total # of //appplo 13 name comes in the file and 3.74 its average
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






Comments

  • bashirobashiro Member Posts: 244
    : hi,
    : i ve' to write a program which read a 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
    : ****************************************************
    :
    : which contain name of movies and their rating "Liar Liar | 5" 5 is its rating. and so on.
    :
    : i ve to calculate its rating average.
    : After i processed all lines from the input file, you collect the Mreview objects(file name) in an ArrayList object by calling toArrayInorder in the BST tree. The Mreview objects are in the alphabetically sorted order by the titles. so the output should in this form:
    :
    : Apollo 13 27 3.740740740740741 //27 is total # of //appplo 13 name comes in the file and 3.74 its average
    : 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
    :
    :
    :
    :
    :
    :
    :



    So what do you want ?
    Do you need help on how to approach the problem ?
    In other words do you need help on how to read the
    input lines or how to sort the array list ?

    bashiro

  • azfariqbalazfariqbal Member Posts: 15
    : : hi,
    : : i ve' to write a program which read a 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
    : : ****************************************************
    : :
    : : which contain name of movies and their rating "Liar Liar | 5" 5 is its rating. and so on.
    : :
    : : i ve to calculate its rating average.
    : : After i processed all lines from the input file, you collect the Mreview objects(file name) in an ArrayList object by calling toArrayInorder in the BST tree. The Mreview objects are in the alphabetically sorted order by the titles. so the output should in this form:
    : :
    : : Apollo 13 27 3.740740740740741 //27 is total # of //appplo 13 name comes in the file and 3.74 its average
    : : 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
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    :
    :
    :
    : So what do you want ?
    : Do you need help on how to approach the problem ?
    : In other words do you need help on how to read the
    : input lines or how to sort the array list ?
    :
    : bashiro

    hi,
    yes, please.
    thanks
    :
    :

  • chamsterchamster Member Posts: 662
    : : ...do you need help on how to read the
    : : input lines or how to sort the array list ?

    : yes, please.

    I think he ment - pick one now and save the other for later when you're finished with the first :-)



    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

  • ShinMagusShinMagus Member Posts: 24
    : : : ...do you need help on how to read the
    : : : input lines or how to sort the array list ?
    :
    : : yes, please.
    :
    : I think he ment - pick one now and save the other for later when you're finished with the first :-)
    :
    :
    :
    : Kind Regards
    : Konrad
    : ----------------------------
    : (+46/0) 708-70 73 92
    : chamster@home.se
    : http://konrads.webbsida.com
    :
    :

    You could use a StringTokenizer in order to separate what comes before and after the "|"...


    import java.util.StringTokenizer;

    String str = "the line";
    StringTokenizer st = new StringTokenizer(str, "|");
    while(st.hasMoreTokens())
    {
    String s = st.nextToken();
    //do whatever you wish with the string you just obtained
    }



  • azfariqbalazfariqbal Member Posts: 15
    : : : ...do you need help on how to read the
    : : : input lines or how to sort the array list ?
    :
    : : yes, please.
    :
    : I think he ment - pick one now and save the other for later when you're finished with the first :-)
    :
    :
    :
    : Kind Regards
    : Konrad
    : ----------------------------
    : (+46/0) 708-70 73 92
    : chamster@home.se
    : http://konrads.webbsida.com
    :
    : hi,
    i have to read that how many time the name of movie appears in the text like applo 13 apears 27 times suppoes than find out its average and so on .

  • chamsterchamster Member Posts: 662
    OK, so you open a file, read in the text, line after line. Then you use the StringTokenizer-class as somebody already told you.

    Do you need help with the specific code for reading a text file?



    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

  • azfariqbalazfariqbal Member Posts: 15
    : OK, so you open a file, read in the text, line after line. Then you use the StringTokenizer-class as somebody already told you.
    :
    : Do you need help with the specific code for reading a text file?
    :
    :
    :
    : Kind Regards
    : Konrad
    : ----------------------------
    : (+46/0) 708-70 73 92
    : chamster@home.se
    : http://konrads.webbsida.com
    :
    :
    Hi
    yes I need a code to start can u please help me out

  • chamsterchamster Member Posts: 662
    Here you go:
    [code]
    try
    {
    BufferedReader reader = new BufferedReader (new FileReader ("filename.txt"));
    String txt = "";
    for (String row = reader.readLine (); row != null; row = reader.readLine ())
    txt += row;
    reader.close ();
    }
    catch (Exception e) { }
    [/code]



    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

  • chamsterchamster Member Posts: 662
    I forgot to add - if you'd like the contents of the file to be used somewhere else (as for instance outside the try-catch), simply declare the String txt before the try-catch.


    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    ____ ( http://forcoder.org ) free video tutorials and ebooks about < Delphi, Python, R, Perl, Objective-C, C#, Go, Java, C, Visual Basic .NET, Ruby, PHP, Swift, C++, Assembly, Visual Basic, MATLAB, Scratch, JavaScript, PL/SQL Scheme, Apex, FoxPro, Kotlin, Scala, Erlang, Alice, Rust, F#, Julia, D, ABAP, Ada, COBOL, Lisp, VBScript, LabVIEW, Bash, Dart, Clojure, Transact-SQL, Hack, SAS, Lua, Fortran, ML, Awk, Prolog, Crystal, Logo /> ___

Sign In or Register to comment.