Need help with an assignment

Need help with an assignment
[11405 byte] By [Kodenza] at [2007-11-27 5:24:35]
# 1
If you do a hangman class and invoke methods from main method it's quite easier.Do you know how to do that?
totua at 2007-7-12 11:50:49 > top of Java-index,Java Essentials,New To Java...
# 2
I kind of do. My teacher told me the same thing. Only thing is, when I tried to do it, I got the same messed up results.
Kodenza at 2007-7-12 11:50:49 > top of Java-index,Java Essentials,New To Java...
# 3

I think you should design your application.

Get a pencil, a rubber and some paper and start making a Nassi-Schneiderman diagram where you invoke methods like hangMore(), correctInput() or kill() without entering in low level code.

If you do that you are not gonna be puzzled by loops.

totua at 2007-7-12 11:50:50 > top of Java-index,Java Essentials,New To Java...
# 4

> I think you should design your application.

> Get a pencil, a rubber and some paper and start

Before we start snickering, let's remember today is cultural sensitivity day!

An Indian friend of mine at university told me a classic story of this:

he was at the campus store and asked, "where can I buy a rubber?

The one I have is old and worn out because I'm so tough on it."

> making a Nassi-Schneiderman diagram where you invoke

> methods like hangMore(), correctInput()

Who that? UML not good enough for you ;-)

[url #" style="display: block; background-image: url('http://upload.wikimedia.org/wikipedia/en/thumb/1/17/Multiple_Branching.JPG/800px-Multiple_Branching.JPG'); width: 800px; height: 354px] [/url]

Freaky...

Hippolytea at 2007-7-12 11:50:50 > top of Java-index,Java Essentials,New To Java...
# 5
UML it's ok, but for someone that it's making a Java course on highschool, I think should be easier to use an simple and structured diagram (It works perfect to design hangman game, as long as I used that method two years ago).Message was edited by: totu
totua at 2007-7-12 11:50:50 > top of Java-index,Java Essentials,New To Java...
# 6

> > I think you should design your application.

>

> > Get a pencil, a rubber and some paper and start

>

> Before we start snickering, let's remember today is

> cultural sensitivity day!

Read here for relevant information about rubbers: http://ftvdb.bfi.org.uk/sift/title/114070

DrClapa at 2007-7-12 11:50:50 > top of Java-index,Java Essentials,New To Java...
# 7

> I kind of do. My teacher told me the same thing. Only

> thing is, when I tried to do it, I got the same

> messed up results.

Merely putting the code into seperate methods will not fix the results. It will make it easier to fix the results.

And I agree about getting some design in place. Close all your code and write it out on paper. Think about what behaviour a hangman game will need, and then write those methods. That's a better approach than just taking your existing code and randomly breaking it into sub-parts a(), b(), and c().

bheilersa at 2007-7-12 11:50:50 > top of Java-index,Java Essentials,New To Java...
# 8

Here is what I would do:

~Create a class (ex: WordChooser ) which chooses a random word from a list.

~Create a method in another class ( WordChecker ) which runs the letter entered by the user and compares it to the word chosen by the WordChooser class, looking for a similar letter.

Add 2 more methods in the WordChecker class to make arrays for right and wrong letter guesses. Make the right guess array which checks the # of characters in word chosen by WordChooser. Then start off with everything = "_". Once a correct letter is guessed, it would find the correct array # to change to the right letter guessed, then this would be accessed by the HangmanDisplayer class and printed into the terminal.

The wrong guess array would be much easier, just tack on wrong letter guesses and access it with the HangmanDisplayer.

~Create the main class HangmanDisplayer, it will contain all of the hanger's beautiful ASCII art, ready to be printed to the terminal.

Doing that will allow you to expand the word list, and even probably add a GUI and Java2D in the HangmanDisplayer class. I bet your teacher will like the fact that you are using 3 classes too.

kavon89a at 2007-7-12 11:50:50 > top of Java-index,Java Essentials,New To Java...
# 9
Creating 3 classes might be helpful. The way you explained it makes sense, but I'm not quite sure how to use 3 different classes for one program.
Kodenza at 2007-7-12 11:50:50 > top of Java-index,Java Essentials,New To Java...
# 10

Then perhaps your need to go back and review basics of Objects. Here's a quick and simple example.

class Foo {

public void execute() {

Bar b = new Bar();

b.run();

}

public static void main(String[] args) {

Foo f = new Foo();

f.execute();

}

}

class Bar {

public void run() {

System.out.println("Hello World");

}

}

floundera at 2007-7-12 11:50:50 > top of Java-index,Java Essentials,New To Java...