Results 1 to 13 of 13
Thread: Why can not run?
- 03-01-2009, 04:00 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 19
- Rep Power
- 0
Why can not run?
PHP Code:import java.util.*; import java.text.*; import java.io.*; public class wordCount2 // a very simple driver class { static final String USAGE="Usage:java wordCount2 files(s)"; static String fi,fo; public static void main(String args[]) { WC_Model model = new WC_Model(); if (args.length != 2) {System.out.println(USAGE); return;} if (args.length>0) {fi=args[0];fo=args[1];} model.runFile(fi,fo); model.showRanMsg(); } } class WC_Model { static boolean isRpt=false; static int t,tok,top,tokenCount; static String inFileName,intext,outFileName; static int wc[]=new int[500],wordCounts[]=new int[500]; static String w[]=new String[500],words[]=new String [500]; // class constructor and initializer public WC_Model() {top=0;tokenCount=0;} // observer methods for external display of results public String getData() { String data=new String(""), buf=new String(); TextIO io=new TextIO(); File fi = new File(inFileName); io.openText(fi,"read"); while ((buf=io.readText())!=null) {data+=buf+"\n";} io.closeText("read"); return data; } public int getTop() {return top;} public int getTok() {return tokenCount;} public int[] getWordCounts() {return wordCounts;} public String[] getWords() {return words;} // action method that does the analysis public void doCount(String msg) { String tokDelim=" \t\n\r\f,.;:~!@#$%^&*()+={}[]<>/\""; String buf=new String(),token=new String(); StringTokenizer st; buf=msg; st=new StringTokenizer(buf,tokDelim);tokenCount+=st.countTokens(); while (st.hasMoreTokens()) // make sure there are words to count { token=st.nextToken().toLowerCase(); // get token & decase // now search the array for existing occurance of word Boolean found=false; for (int idx=0; idx<=top; idx++) { if (token.equals(words[idx]) ) // is it in list already { wordCounts[idx]++; found = true; idx = top + 1;} } if (found == false) {words[top] = token; wordCounts[top] = 1; top++;} // new word } } public void runReport() { DecimalFormat df = new DecimalFormat("00000"); //fixed posn SimpleDateFormat sdf=new SimpleDateFormat("yyyy MMM dd @ hh:mm"); Date date = new Date(); String rptDate = sdf.format(date); TextIO io = new TextIO(); File fo = new File(outFileName); io.openText(fo,"write"); for (int idx=0;idx<t;idx++) // display the results {io.writeText(df.format(wc[idx])+" "+w[idx]);} io.writeText("-------------------"); io.writeText(df.format(tok)+" words in text!"); io.writeText(df.format(t) +" unique words in text!"); io.writeText("!"+"wcPlus report created on "+rptDate+"\n"); io.closeText("write"); isRpt = true; } public void runFile(String s, String d) { inFileName=s;outFileName=d; // source and destination intext = getData(); // get contents of WS doCount(intext); // let class do the work tok = getTok();t=getTop(); // fetch the results w = getWords(); wc = getWordCounts(); runReport(); } public void showRanMsg() { if (isRpt) {System.out.println("Report has been created");} } }
-
Are you getting any error messages? Is nothing happening at all? Please understand that the more detail you provide, the more specific the question, the greater our ability to help you. Good luck.
- 03-01-2009, 04:54 AM #3
Member
- Join Date
- Feb 2009
- Posts
- 19
- Rep Power
- 0
no errors...but it suppose to print out somethings when i run the command right? if i dont misunderstand it...it just print nothing except the USAGE string...
-
Then you're obviously using it wrong. Tell me,
1) what conditions will cause the usage string to be displayed?
2) have you corrected for these conditions?
3) is this your code? (I already know the answer to this, and so...)
4) whose code is this and how is it in your possession and what is your goal with it?
- 03-01-2009, 05:16 AM #5
Member
- Join Date
- Feb 2009
- Posts
- 19
- Rep Power
- 0
this is not my code...As i trying to learn about io...i need to understand it...i really dont know whether this code got problems or not....i suppose to print this...when i run the command to scan the text from a external text document right?
PHP Code:for (int idx=0;idx<t;idx++) // display the results {io.writeText(df.format(wc[idx])+" "+w[idx]);} io.writeText("-------------------"); io.writeText(df.format(tok)+" words in text!"); io.writeText(df.format(t) +" unique words in text!"); io.writeText("!"+"wcPlus report created on "+rptDate+"\n"); io.closeText("write"); isRpt = true; }
-
Let's look at what happens when you run the program though. You tell me that the USAGE String is shown, correct? If so, then the reason is obvious from this line in the program:
So, my next question of course is what parameters are you passing to this program when you run it? Do you pass it the input and output file names?Java Code:if (args.length != 2) {System.out.println(USAGE); return;}
- 03-01-2009, 05:31 AM #7
Member
- Join Date
- Feb 2009
- Posts
- 19
- Rep Power
- 0
do u mean enter the command "java wordCount2 filename"?If so,i did...PHP Code:So, my next question of course is what parameters are you passing to this program when you run it? Do you pass it the input and output file names?
- 03-01-2009, 05:39 AM #8
ah... that thick plottens...
What is the above telling you? Please explain. This will tell you what you have to do (like Fubarable commented).Java Code:if (args.length != 2) {System.out.println(USAGE); return;}
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 03-01-2009, 05:50 AM #9
Member
- Join Date
- Feb 2009
- Posts
- 19
- Rep Power
- 0
args.length is not equal to 2...means not equal to 2 words?
-
Yep, 2 it needs to have words passed to the program. Your post above only shows one word. If you delve deeper into the code, the first word appears to be the name of the input file and the second the name of the output file.
- 03-01-2009, 05:58 AM #11
Bingo !!! Give the man a cigar !!! yep 2 words... which are actually two names, which represent the names of two files, one an input file and the other an output file.
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 03-01-2009, 06:00 AM #12
Member
- Join Date
- Feb 2009
- Posts
- 19
- Rep Power
- 0
i think i know what's wrong already...thanks ya....
- 03-01-2009, 06:02 AM #13
Member
- Join Date
- Feb 2009
- Posts
- 19
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks