![]() |
Hangman
Hi,
Before I begin, I am not asking anyone to do my homework for me, I know that is against forum rules. I just need a little help on where to start. I have a CS assignment, and we have to make a hangman program. The basic output should be (if the word is "computer"): :
_ _ _ _ _ _ _ _ // # of blanks = word.length()Our teacher is not allowing us to use string buffers, and I'm not really sure what to do. I get the basic idea of how to change the hangman, how to determine the winner, and such but I'm not sure what I'm supposed to start with when I display the blanks and how to update them (the game part). The list of words is imported from a word.txt file. So all the words come from an arraylist. Any tips would be greatly appreciated. Thanks. |
Write some code (we won't write it for you). We'll help you fix it. This is a common homework question, seen a dozen times a year.
|
I know this is horrifically bad code, but I'm a noob.
:
import java.io.*;when i try to test this, i get a null pointer exception. |
Sure you do. In getList(), you use the variable "list" without ever initializing it. And that's probably not the only variable you do so with. I don't see "master" initialized anywhere either.
|
That wasn't the problem I was having because I hadn't tested that part yet. I fixed how the words are gathered, and I know the arraylist for the input is working fine. I am trying to test the "getBlanks" method but it is just outputting "null".
this is test.java: :
import java.io.*;this is input.java :
I am really lost. :confused: |
fixed the "null" thing but I'm getting the null pointer. Where am i supposed to initialize it?
|
I don't see "ArrayList<String> used" initialized anywhere, do you?
|
Well, ya, i fixed that. But the null pointer is coming in the "getList" method
:
for(int y=0; y<=masterwords.size(); y++)thats the section im testing, and it gives me an error in the if statement. I'm not sure whats going on. |
| All times are GMT -5. The time now is 3:14 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC