User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 426,187 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,822 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1003 | Replies: 4
Reply
Join Date: May 2007
Posts: 5
Reputation: javageak is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
javageak javageak is offline Offline
Newbie Poster

Help <b>TextFileStats.java need help!</b>

  #1  
May 2nd, 2007
I really need help with this code...I have to display statistics from each and use Scanner and Tokenizer. For displaying each character I have to use Character.isLetter(). Please help me figure out how to display all of these things from a file.

//TextFileStats.java
//Print out Statistics using StringTokenizer.
import java.io.*;
import java.util.*;
import java.lang.*;

publicclass TextFileStats
{
publicstatic Scanner scanner;
publicstaticint wordCount;
publicstaticint paragraphCount;
publicstaticint charPerWordCount;
publicstaticint sentenceCount;
publicstaticint lineCount;
publicstaticint charCount;

publicstaticvoid main( String args[] ) throws IOException, NumberFormatException, FileNotFoundException
{
scanner =
new Scanner( new File( "C:\\README.txt" ) );

while( scanner.hasNext() )
{
String input = scanner.nextLine();
StringTokenizer tokenizer =
new StringTokenizer( input );
lineCount++;

while ( tokenizer.hasMoreTokens() )
{

tokenizer.nextToken();
wordCount = 0;
wordCount++;

String character = tokenizer.nextToken();
boolean isCharacter = false;
int = 0;
while( i < tokenizer.length() && isCharacter )
{
String ch = tokenizer.substring( i, i + 1 );
if( ch.compareTo
charCount = Integer.parseInt( tokenizer.nextToken() );

charPerWordCount = Integer.parseInt( tokenizer.nextToken() );

sentenceCount = Integer.parseInt( tokenizer.nextToken() );

paragraphCount = Integer.parseInt( tokenizer.nextToken() );

}
}
//end StringTokenizer
scanner.close();

//print out statistics
System.out.println( "Page count: " + lineCount/60 );
System.out.println(
"Word count: " + wordCount );
System.out.println(
"Character count: " + charCount);
System.out.println(
"Character per word count: " + charPerWordCount );
System.out.println(
"Sentence count: " + sentenceCount );
System.out.println(
"Paragraph count: " + paragraphCount );
}
}

AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,453
Reputation: peter_budo is a jewel in the rough peter_budo is a jewel in the rough peter_budo is a jewel in the rough peter_budo is a jewel in the rough 
Rep Power: 11
Solved Threads: 296
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: TextFileStats.java need help!

  #2  
May 3rd, 2007
Isn't enough to place an incomplete question on the forum?
Do you have to spawn people with private messages?

So what is your question? Looking at what you quick typed without thinking, you are supposed to creare program that will read a text file, count ocurence of each character and provide statistics on how many times each character appeared in the text. For the purpose of your homework, you have to use Scanner, StringTokenizer and method isLetter(). I'm corect?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: May 2007
Posts: 5
Reputation: javageak is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
javageak javageak is offline Offline
Newbie Poster

Help Re: <b>TextFileStats.java need help!</b>

  #3  
May 3rd, 2007
Yes that is correct. I need a program that will read in a file that will count each character, word, character per word, sentence, and paragraphs and I need to use StringTokenizer, Scanner, and Character.isLetter().

I know it isn't completely finished, that's why I need help, because I am somewhat clueless on which method I should choice.
Reply With Quote  
Join Date: May 2007
Posts: 5
Reputation: javageak is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
javageak javageak is offline Offline
Newbie Poster

Help Re: <b>TextFileStats.java need help!</b>

  #4  
May 3rd, 2007
I have completed most of my code, I just need help with counting how many paragraphs are on the text file.

//Stephen Kutner
//TextFileStats.java

import java.io.*;
import java.util.*;

publicclass TextFileStats
{
publicstatic Scanner scanner;

publicstaticint wordCount = 0;

publicstaticint paragraphCount = 0;

publicstaticint charPerWordCount = 0;

publicstaticint sentenceCount = 1;

publicstaticint lineCount = 0 ;

publicstaticint charCount = 0 ;

publicstatic String word = " ";

publicstaticvoid main(String args[]) throws IOException, NumberFormatException, FileNotFoundException,
ArrayIndexOutOfBoundsException, NegativeArraySizeException
{

scanner =
new Scanner(new File("C://README.txt"));
while (scanner.hasNext())
{
String input = scanner.nextLine();
StringTokenizer tokenizer =
new StringTokenizer(input);
charCount = charCount + input.length();
lineCount = lineCount + 1;

while (tokenizer.hasMoreTokens())
{
word = tokenizer.nextToken();
wordCount = wordCount + 1;

for( int i = 0; i < wordCount; i++ )
{
if( Character.isLetter('.') == true )
{
sentenceCount = sentenceCount + 1;
}
}

for( int j = 0; j < wordCount; j++)
{
if( Character.isSpace('\n') == true )
{
charPerWordCount = charPerWordCount + 1;
}
}
paragraphCount = paragraphCount + 1;
}
}
// end StringTokenizer
scanner.close();

// print out statistics
System.out.println( "Page count: " + lineCount/60 );
System.out.println(
"Word count: " + wordCount );
System.out.println(
"Line Count: " + lineCount );
System.out.println(
"Character count: " + charCount );
System.out.println(
"Character per word count: " + charPerWordCount );
System.out.println(
"Sentence count: " + sentenceCount );
System.out.println(
"Paragraph count: " + paragraphCount );
}
}
//end TextFileStats.java

Reply With Quote  
Join Date: Aug 2005
Posts: 4,782
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 319
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: <b>TextFileStats.java need help!</b>

  #5  
May 3rd, 2007
>I just need help with counting how many paragraphs are on the text file.

Ask yourself how you define a paragraph, then write the code to do it.
I'm not a programmer. My attitude starts with ignorance, holds steady at conversation, and ends with a trip to the hospital. Get used to it.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 6:42 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC