Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Outputting number of times words appear to end user

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!





 
Marshal
Posts: 75690
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
  •  
    Seriously Rick? Seriously? You might as well just read this tiny ad:
    free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
    reply
      Bookmark Topic Watch Topic
    • New Topic