• 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

Hangman program

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I am making this Hangman program but the twist is that it doesn't actually pick a word until it has to. The way that this is accomplished is that you start off with a list of words (a dictionary.txt file is what I use, it has a ton of words in it), how many guesses you want and the word size. Then, you give the program a letter to guess. After you give it a letter, what is supposed to happen is that it creates different "word families", based on that letters location in it. Let's say that I guess "a" for a four letter word- there would be a family of "----", a family of "--a-", a family of "-a--", etc. I want to use these strings as keys ("----", "--a-", etc) and have the words that match them be the values in a map.

My problem is that I can't figure out how to do this. If I said I wanted four letters, then every four letter word in the dictionary would go into a set. I want to be able to create different word families after the user guesses, then pick the one with the largest amount of words in it (thus how you can cheat the user), but I can't figure out how to do this. Sets don't have a get method, so I'm not really sure how I am supposed to check each character of each word to see if it matches with the guess. How would I do this? Am I supposed to use an iterator, and if I am how so?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first step in writing any program is to NOT think in terms of what a language gives you, but how YOU would do it, if you had nothing but paper and pencil. Don't think about java's maps or hashtables or iterators...think in English (or any natural language you prefer) and figure out the steps as if explaining it to a child.
 
Tyler Tallman
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried doing that but I can't figure out how I'm going to code it. Also, I am having trouble with how I am going to assign values to the keys. Each value needs to be a set full of words that match up with "----", "-a--", etc. But I can't figure out how I am just going to create and fill sets on the fly like that, as I am fairly sure that you can't create new sets within a loop.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try guessing. You will end up with code which looks a total mess, takes weeks to write, and gives some sort of answer. You will get a scrape pass. You will post it here, and I shall tell you to use ctrl‑A→delete on your code.
Or you can do it properly, which involves what Winston G always says, “turn your computer off” and doing what Fred has told you. But you need my usual enhancement of that technique: an eraser A large one!
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tyler Tallman wrote:I tried doing that but I can't figure out how I'm going to code it


At this stage, you SHOULDN'T be thinking about how you are going to code it. You should be thinking about how to solve the problem in ENGLISH. There is no coding at this point.
 
reply
    Bookmark Topic Watch Topic
  • New Topic