CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Oct 2011
    Posts
    2

    [Edited version] Read/scan textfile in java. Still need help

    Hey all.

    So I got a schoolproject in java, and I'm going to read/scan a text file.
    But the tricky part is: My javaprogram contains a question of how many lines of the text file I want to show.
    And also, display them in my output.

    Theres more to the this program that I've listed here. But I want to try to figure most of this out by myself. But I'm just stuck here

    btw, the text file (verb.txt) contains 88 different verbs, and the program is going to be a "teaching" program. The user is going to type in how many verbs she want to be tested in. If she puts in ex. 5, she will generate 5 random verbs.
    But, the verbs got one word "blurred" out. And the users object is to type in the missing word.

    Like so:

    Type in desired amount of verbs: 5

    ... - was - been
    Type in what is missing: be
    ... - beat - beaten
    Type in what is missing: beat
    become - became - ...
    Type in what is missing: becom
    ... - bound - bound
    Type in what is missing: bound
    Wrong: bind

    My java:
    public static void verbTxt() {
    Scanner input = new Scanner (System.in);
    System.out.println("\nType in desired amount of verbs: ");
    int tallSvar = input.nextInt();
    if(tallSvar = ......){
    /* what_to_do?...(); */

    }
    File textFile = new File ("verb.txt");
    try {Scanner fileInput = new Scanner (textFile);
    }

    catch (FileNotFoundException exc) {
    System.out.println("\nFile was not found.");
    }
    }
    }

    Edit:
    Ok, my problem is that I don't have a clue on how I can read/scan the text file (verb.txt).
    Because I'm going to scan it, (the file contains of 88 verb grammar that is listed like this (this is the 7 first:
    be was been
    beat beat beaten
    become became become
    begin began begun
    bind bound bound
    blow blew blown
    break broke broken )

    And the user is going to use the java program as a teaching device. This is done by letting the user type in how many verbs she wants to get shown (using input.nextString for example) (lets say 3 verbs this time). The program will randomly find 3 different verbs, and show it in the output.
    But one of the words is "dot'ed" (...) out. Where the field is dot'ed out, the user have to type in what he/she thinks is the correct verb/answer (using input.nextString for example). The user is going to type her next.input answer after one verb. The java program will tell the user if the answer (next.input) is correct or not.


    So this is how I imagined the output should be. Underlined text = user input value:

    /* Program asks for how many verbs the user wants to get listed */
    Type in desired amount of verbs: 5 /* via. next.input the user can type in how many verbs he/she wants to get listed */

    /*program will not list 5 randomly fetched verbs from the file. As commanded by the user. But after every verb listed, the user can type in her answer. If the users next.input/answer is correct. The program will continue to the next verb in the list.*/
    ... - was - been
    Type in what is missing: be /* answer is correct, the program continues to the next verb */
    ... - beat - beaten
    Type in what is missing: beat /* answer is correct, the program continues to the next verb */
    become - became - ...
    Type in what is missing: become /* answer is correct, the program continues to the next verb */
    ... - bound - bound
    Type in what is missing: bound /* answer was wrong, the program tells the user what is the correct answer */
    Wrong: bind

    That's the output I wish to achieve. Thanks for the help btw mr. Norm.
    Last edited by instinctx; November 22nd, 2011 at 06:44 PM.

  2. #2
    Join Date
    Oct 2011
    Posts
    2

    Re: Read/scan textfile in java. But there's more to it! Help

    Thanks for any answers btw

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured