• Post Reply Bookmark Topic Watch Topic
  • New Topic

Outputting number of times words appear to end user  RSS feed

 
Matthew Cooper
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good morning,

I am trying to create a program that will output to the end user how many times all words appear in a txt document. I am running into 2 issues here that I am hoping someone can help me out with. First of all I have 2 classes. The first class (CrazyWords) asks the user for the name of a text file. It will either then say that it found the file or will say it cannot find the file, that part is working fine. The second class (WordCounter) is supposed to take whatever the text file that was entered in CrazyWords and then in turn output the number of times every word appears to in the text file. I can get this working if I know the name of the file, but the thing is I wont always know the name of the file that the user wants. I also want them to work as one program and not 2 separate programs. Any help would be greatly appreciated!!





 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I can see some things which you are doing wrong.
  • 1: You have everything in the main method. You shouldn't. You should have lots of small methods which do different things. A good example of what a main method should look like is to be found here.
  • 2: What is the relationship between the two classes. If they only have main methods, they are independent of each other, whereas they ought to be designed to cooperate with each other.
  • 3: Are you trying to do too much all at once? Do one thing, e.g. print out all the words in your file, and be sure that works correctly, before you try something else, e.g. counting.
  •  
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!