Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 28th, 2005, 4:56 PM   #1
Nano
Newbie
 
Nano's Avatar
 
Join Date: Aug 2004
Location: Hacienda Heights, CA
Posts: 8
Rep Power: 0 Nano is on a distinguished road
Send a message via AIM to Nano Send a message via MSN to Nano Send a message via Yahoo to Nano
Help: Program Count Words

Hi Everyone, I am currently work on a program CountWords. I use JCreator, the program should

A)Count total words that are in a text file.

B)Count special cases words used

C)Count top 30 words that occur most frequently, store them in descending order

*Special Cases are
sixty-three counts as one word
joyous - sparkling counts as two words, the hyphen(-) will have a blank space on each side
'tis counts as one word
can't counts as one word
Capitalize words and uncapitalized words are the same

So far, I finally finished reading a text file and print out the numbers inside the text file
import java.util.*;
 import chn.util.*;
 
 class Countwords
 {
 	private int myHowMany;
 	private int [] myList=new int[400];
 	
 	public void readFile(String fileName)
	{
		int index=0;
		FileInput inFile= new FileInput(fileName);
		myList[index]=inFile.readInt();
			
		while(inFile.hasMoreTokens())
		{
			index++;
			myList[index]=inFile.readInt();
		}
			
		myHowMany=index;
	}
	
	public void printFile()
	{
		int x;
		
		for(x=0;x<=myHowMany;x++)
			System.out.print(myList[x]);
		System.out.println();
	}
 }
 
 class driver
 {
 	public static void main(String[]args)
	{
		Countwords driver = new Countwords();
		
		driver.readFile("countwords.txt");
		driver.printFile();
	}
 }

Can somebody help me step by step? I am trying to print out words from a text file, not numbers.....I've only gone to print out numbers so far, but I don't know how to print out words...

Thankyou in advance for reply
__________________
why....why u.s. citizen.............
Nano is offline   Reply With Quote
Old Jan 28th, 2005, 5:22 PM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
I'm a little pressed for time at the moment, so I unfrotunately can't walk you through this step by step. On the other hand, I can give you basic guidelines to look up that will hopefully help you.

Look up the Comparable interface, the Collections class, ArrayLists, and the split() method under the String class. If you still need further help tomorrow, I'll be glad to walk you through.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Jan 29th, 2005, 2:13 AM   #3
Nano
Newbie
 
Nano's Avatar
 
Join Date: Aug 2004
Location: Hacienda Heights, CA
Posts: 8
Rep Power: 0 Nano is on a distinguished road
Send a message via AIM to Nano Send a message via MSN to Nano Send a message via Yahoo to Nano
Red face

thankyou for helping me, but how do I look up those classes?
__________________
why....why u.s. citizen.............
Nano is offline   Reply With Quote
Old Jan 29th, 2005, 8:08 AM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Google is your friend.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jan 29th, 2005, 8:35 AM   #5
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
I'm planning on learning java next month, but has that ever stopped me before?

[php]import java.util.*;
import chn.util.*;

class Countwords
{
private int myHowMany;
private int index = 0;
private int [] myList=new int[400];

public void readFile(String fileName)
{
FileInput inFile= new FileInput(fileName);
myList[index]=inFile.readInt();

while(inFile.hasMoreTokens())
{
index++;
myList[index]=inFile.readInt();
}

int count = 0;
for(int i=0;i<=index;i++) {
if(myList[i] == " ") count++;
if(myList[(i==0)?0:i-1] == "-" or myList[i+1] == "-") count--;
}

myHowMany = count;
}

public void printFile()
{
int x;

for(x=0;x<=index;x++)
System.out.print(myList[x]);
System.out.println();
System.out.println("Number of words is: ");
System.out.print(myHowMany);
}
}

class driver
{
public static void main(String[]args)
{
Countwords driver = new Countwords();

driver.readFile("countwords.txt");
driver.printFile();
}
}[/php]
__________________

tempest is offline   Reply With Quote
Old Jan 29th, 2005, 10:22 AM   #6
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Quote:
Originally Posted by Nano
thankyou for helping me, but how do I look up those classes?
If you look up Javadocs on google, you'll find those.

Collections
ArrayList
String
Comparable
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Jan 30th, 2005, 9:40 PM   #7
Nano
Newbie
 
Nano's Avatar
 
Join Date: Aug 2004
Location: Hacienda Heights, CA
Posts: 8
Rep Power: 0 Nano is on a distinguished road
Send a message via AIM to Nano Send a message via MSN to Nano Send a message via Yahoo to Nano
umm java docs! thankyou for telling me!
I will work on this program more, and ask for help if I need.
Thankyou all!
__________________
why....why u.s. citizen.............
Nano is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:55 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC