Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: Reading text file and counting the number of words, integers, and floats.

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Reading text file and counting the number of words, integers, and floats.

    Need this thread deleted. No longer need help.
    Last edited by Jsmooth; April 12th, 2012 at 07:14 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Reading text file and counting the number of words, integers, and floats.

    Can you post the program's output and also post what the output should be.

    For testing I'd use as small a file as possible so it is easy to see which numbers are wrong.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Reading text file and counting the number of words, integers, and floats.

    The number of integers in the file is 64 and the number of words is 29 the number of floats is 3
    >
    Last edited by Jsmooth; April 12th, 2012 at 07:14 PM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Reading text file and counting the number of words, integers, and floats.

    Are the count like this:
    wrong vs correct
    64 vs 129 ints
    29 vs 30 words
    3 vs 68 floats
    0 vs 6 invalid
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Reading text file and counting the number of words, integers, and floats.

    I told you, "The number of integers in the file is 64 and the number of words is 29 the number of floats is 3"

    But this is wrong so my code isn't correctly counting them right. Which is what I can't figure out.

  6. #6
    Junior Member
    Join Date
    Apr 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Reading text file and counting the number of words, integers, and floats.

    Quote Originally Posted by Norm View Post
    Are the count like this:
    wrong vs correct
    64 vs 129 ints
    29 vs 30 words
    3 vs 68 floats
    0 vs 6 invalid
    Yeah! That's my problem. I'm still trying to play around with my code but still not getting correct results.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Reading text file and counting the number of words, integers, and floats.

    Try debugging the program by adding printlns to the code that track the execution and show the results of each test line by line and value by value.

    Print out each line as it is read, then print out the counts after that line is scanned and the counts made.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Apr 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Reading text file and counting the number of words, integers, and floats.

    Quote Originally Posted by Norm View Post
    Are the count like this:
    wrong vs correct
    64 vs 129 ints
    29 vs 30 words
    3 vs 68 floats
    0 vs 6 invalid
    Sorry my mistake, it is suppose to be
    Last edited by Jsmooth; April 12th, 2012 at 07:14 PM.

  9. #9
    Junior Member
    Join Date
    Apr 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Reading text file and counting the number of words, integers, and floats.

    Quote Originally Posted by Norm View Post
    Try debugging the program by adding printlns to the code that track the execution and show the results of each test line by line and value by value.

    Print out each line as it is read, then print out the counts after that line is scanned and the counts made.
    I have done everything. Been spending multiple hours figuring ways to debug it and have it print the correct amount for each one. Do you think my methods are not checking the integers, floats, and words correctly?

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Reading text file and counting the number of words, integers, and floats.

    Make a small input file, add printlns as I described to print out the results as each line is read.
    Execute the program and look at the output and see if it is correct. If not then add more printlns to the methods where the count is not correct to see why that method is not doing what you want.
    If that file has no errors, replace the input file with another small file with few lines and run it again. You need a small test file that will be counted incorrectly. Then you can work on the methods that are not working correctly.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Apr 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Reading text file and counting the number of words, integers, and floats.

    I have been doing that. I have now got it to get the correct number of words. The number of integers and floats is what I can't get nor the invalid ones. Can you actually look at my code and see what you would do? I'm really stressing over this...

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Reading text file and counting the number of words, integers, and floats.

    Did you print out some of the integers and floats that were counted incorrectly?
    Can you post them and the debug print outs from the methods that tested them?

    Write a simple testing program that uses one of the integers that the method fails to detect and call the method with it. Print out everything that the method does to see where the logic is wrong.

    I don't see where your code counts the number of invalids.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Can't figure out how to print out number of lines and words in a file in c++
    By javapenguin in forum Other Programming Languages
    Replies: 1
    Last Post: January 29th, 2012, 07:53 PM
  2. Reading file of floats into array list and sorting into subsets
    By Skave in forum Collections and Generics
    Replies: 2
    Last Post: November 9th, 2011, 07:03 PM
  3. [SOLVED] Reading integers from a file, but it's only displaying the first number repeatedly..?
    By jessica202 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 29th, 2011, 08:16 AM
  4. Counting Words in a File with a Loop
    By bengregg in forum Loops & Control Statements
    Replies: 17
    Last Post: February 11th, 2011, 10:11 AM
  5. counting words of a text file
    By maybach230 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: May 6th, 2010, 03:40 PM