![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
|
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............. |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
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.
__________________
"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." - Dwight D. Eisenhower |
|
|
|
|
|
#3 |
|
Newbie
|
thankyou for helping me, but how do I look up those classes?
__________________
why....why u.s. citizen............. |
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
|
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
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]
__________________
|
|
|
|
|
|
#6 | |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Quote:
Collections ArrayList String Comparable
__________________
"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." - Dwight D. Eisenhower |
|
|
|
|
|
|
#7 |
|
Newbie
|
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............. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|