Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By Mmarzex

Thread: Help with a Hangman Project

  1. #1
    Mmarzex is offline Member
    Join Date
    Aug 2011
    Posts
    8
    Rep Power
    0

    Default Help with a Hangman Project

    Hi all,

    So I am currently assigned a project where I have to make a basic hangman game where I am supposed to assign 50 words to a 250-value String class variable. I'm not really sure how I can implement such a thing or for that matter how a setup a String Class Variable like that. The only way I have ever done hangman before is by using a Dictionary class or an array. The book I have this project in is the Java al naturel book, which I'm somewhat impartial to. I originally learned java on my own over the summer by reading the Art & Science of Java which I like a lot more. That being said I have to use the other for the AP Computer Science class I am currently taking. Now the prompt is:

    Hangman: Write Hangman as a subclass of BasicGame. Each word to be guessed should have five letters. Have a 250-letter String class variable that stores 50 possible words to choose at random.* Make sure to take some time thinking about how you plan to do this program BEFORE you start coding.

    BasicGame is a simple frame for making Games for the chapter we are on, it has nothing of importance really to making hangman it just handles all the gui side of the program.

    Now my main question is just how to I go about making the String Variable with 50 words in it and have the program choose a word randomly from that variable?

    Thanks,
    ~Max

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help with a Hangman Project

    First of all, I have to say that in my opinion that is an extremely idiotic requirement, and I don't blame you of course, but whoever made this assignment. They should be taken down to the dungeon and strung up by their private packages. No array? No List? No file?

    Anyway, I suppose you could create some variable

    Java Code:
    public static final POSSIBLE_STRINGS = "after" + "doors" + ..... //ack!
    As to finding a random word -- I'll bet you can figure this one out -- why not give it a try and see what you can come up with?

  3. #3
    Mmarzex is offline Member
    Join Date
    Aug 2011
    Posts
    8
    Rep Power
    0

    Default Re: Help with a Hangman Project

    Yeah there are some really dumb assignments in this book, it isn't an awful book, The problem is it was published in 2002 and hasn't been updated so it is rather outdated. I really feel like this class is not teaching me anything, it isn't teaching me good programming practices or anything. It is really only teaching me how to deal with bad description and explanation to do the exercises and projects. And I'm assuming that if I do what you suggest I would have to do a s.substring call for a random increment of 5 values to get a word. I'm going to try that and see how it turns out.

    Thanks,
    ~Max
    Fubarable likes this.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help with a Hangman Project

    You're welcome, and yeah, Random class has a great method, nextInt(...) that will let you get a random number between 0 and 50.

    Luck!

  5. #5
    Mmarzex is offline Member
    Join Date
    Aug 2011
    Posts
    8
    Rep Power
    0

    Default Re: Help with a Hangman Project

    Okay so I have the choosing of the words set up and working correctly, but I'm somewhat stuck on how I would go about checking the user's guessed letter to see if it is part of the word. I have all the guessed letters going into a String so that it can be checked before a guess is added so no duplicates are added. But I'm not sure how to go about the checking. Any pointers you could give me?

    Thanks

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help with a Hangman Project

    The best pointer I can think of: check out the String API. There are some very useful methods there that you can use.

  7. #7
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Help with a Hangman Project

    Have a 250-letter String class variable that stores 50 possible words to choose at random.*
    This is really ambiguous. Does 250-letter mean you have a single string with a length cap of 250 characters? If so, you would need to make sure your 50 words don't add up to more than 250 chars?

    My guess is that the sentence is crap and the writer had no idea how to convey their meaning.

    I would code this by making an array of strings with a capacity for 50 words. You could then choose a word at rand with the Random class. You could put all of this code in some kind of special 'Dictionary' class that you write yourself with nice accessor methods.

    Now my main question is just how to I go about making the String Variable with 50 words in it and have the program choose a word randomly from that variable?
    Good question, that sounds like an awful requirement. Unless all words were fixed length, you would need to know the offsets of each word. This is a terrible way to do this.

  8. #8
    Mmarzex is offline Member
    Join Date
    Aug 2011
    Posts
    8
    Rep Power
    0

    Default Re: Help with a Hangman Project

    Quote Originally Posted by Fubarable View Post
    The best pointer I can think of: check out the String API. There are some very useful methods there that you can use.
    Alright thanks I will look at that.

    Quote Originally Posted by quad64bit View Post
    This is really ambiguous. Does 250-letter mean you have a single string with a length cap of 250 characters? If so, you would need to make sure your 50 words don't add up to more than 250 chars?

    My guess is that the sentence is crap and the writer had no idea how to convey their meaning.

    I would code this by making an array of strings with a capacity for 50 words. You could then choose a word at rand with the Random class. You could put all of this code in some kind of special 'Dictionary' class that you write yourself with nice accessor methods.



    Good question, that sounds like an awful requirement. Unless all words were fixed length, you would need to know the offsets of each word. This is a terrible way to do this.
    Yeah the project sucks. All the words have to be 5 letter words to ensure that it is a 250 character max for the string. So I just have it doing random increments of 5 to pick a word. I really hate this book, the class is awful but I can't do much about it. I would have used a dictionary and an array as it makes more sense but I have to do it assuming I don't know how to do that yet as we haven't reached that chapter yet and the teacher has already accused me of cheating by using things ahead of what the book is teaching.

  9. #9
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Help with a Hangman Project

    If so, you would need to make sure your 50 words don't add up to more than 250 chars
    Yes, I missed the all words are five letters long requirement too when I read the post.

    Really it's an awful assignment. Name and shame, I say! Computer Science AP A, their web site is at Louisiana Virtual School - Welcome to LVS

Similar Threads

  1. Hangman GUI project
    By aviolently in forum Java Gaming
    Replies: 7
    Last Post: 01-01-2012, 03:12 AM
  2. Hangman
    By Feriscool in forum New To Java
    Replies: 23
    Last Post: 05-17-2011, 07:54 PM
  3. hangman
    By javaMike in forum Advanced Java
    Replies: 2
    Last Post: 11-14-2009, 10:06 AM
  4. Hangman GUI help
    By kurt in forum New To Java
    Replies: 5
    Last Post: 05-22-2009, 11:22 AM
  5. Need help with Hangman!!!
    By chinasome in forum New To Java
    Replies: 10
    Last Post: 11-09-2008, 05:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •