• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about Tree Node --Word Tree

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. I just learned basic stuffs about Tree Node, and I managed to fisnish my first simple program using Tree. Now, I'm challenging second tree program, and it's extremely hard for me...

The direction for this program is as shown below:


The book says that I need to use
%java WordTree"text.txt"count.txt to run this program.
--"text.txt" is the text file that the data is stored.

And...even though I did as the book showed, it keeps showing me errors
that say:



and


Could anyone show me how to fix those errors or show me another way to
creat this program?

Thank You for regarding my question.
And I will appreciate if anyone could give me some help.

Thank you. I hope you have a nice day.
[ March 28, 2005: Message edited by: Taylor Woods ]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you may have forgotten to block the "else" clause. Try:



Henry
[ March 28, 2005: Message edited by: Henry Wong ]
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As well, Integer doesn't have a no-argument constructor.
 
Taylor Woods
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, David and Henry!! After following you guys' instructions, it seems to work. However, there is one problem. For this code, I need to use specific text file and specific command...

What if I want to put the data in this main code istead of putting it in the specific text file so I don't have to use that specific command?

Could you tell me which part I'm supposed to change and how I'm supposed to change? I'm sorry that I'm bothering you too much. Thank you so much.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Taylor Woods:
What if I want to put the data in this main code istead of putting it in the specific text file so I don't have to use that specific command?

I don't follow. You already have it such that the user can specify the input and output file names. Do you want them hard-coded into the class? If so, just define constants instead of using args[0] and args[1], but that's probably not what you mean.

And what command? The "java WordTree" command? You could create a batch file called wordtree.bat:
 
Taylor Woods
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But...I don't know exactly how I should declare the String input in this code. And what do you mean by defining constants? Is it what I just asked you about? If so, how do I do it using args[0] and args[1]?

Since I don't quite understand this code, I hope you could show me exactly how the codes should be.

Oh...and last question~ if I'm going to specify the input file and use it to run the program, how do I run it? It seems to compile ok...but it shows this messayge:


WordTree.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Tool completed successfully


and it doesn't run if I use normal way to run this
which is:


c:\java\bin\java WordTree



If I run this using "c:\java\bin\java WordTree", it syas that


Usage: Word Tree inputfile & outputfile



How can I run this program properly?

Thank you so much for your consideration and help, David. I truly appreciate it.

[ March 29, 2005: Message edited by: Taylor Woods ]
[ March 29, 2005: Message edited by: Taylor Woods ]
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Taylor,
If u don't want to use the arguments in specifying ur input... You can just remove your if-condition check at the beginning of the program...

Instead of
String inputfile = args[0];
String outputfile = args[1];

Just use
String inputfile = textYouWant;
String outputfile = args[0];

But you still need to specify the output file when running your program... But you just need one arguments... Like the following...

java WordTree C:\MyOutputFile.txt

I hope this helps...
reply
    Bookmark Topic Watch Topic
  • New Topic