Hangman, First-pass at Text MVC

  1. The UML class diagram provides a somewhat informative global view of the newly structured program. The solid, gray lines indicate object containment, e.g., a Hangman object contains a GameController object.

    Based on the names/parameters/return types of the methods shown in the diagram and without looking at the code, where is the Word object created that's used in the game (see the diagram for GameController)?

  2. Where is the Gallows object created (and it's degree of difficulty specified?


    You may want/need to look at code to answer the following questions. You may also want to look at The script from a sample run of the program.

  3. The Interface WordFactory is implemented by DefaultWordFactory and the only WordFactory in the program is used in Hangman. How would you change the program to use the default factory or a factory that reads from a file of words?

  4. The letters that have been guessed are "blanked" out and the letters that have not been guessed are displayed prior to the each prompt from the user. Where is the code that prints these letters? How would you modify the code to print only the already guessed letters, not those that have not been guessed? Which is better from a user-interface perspective?

  5. This question requires reasoning and understanding of the Java Observer/Observable interface/class. The Word constructor calls setChanged, but notifyObservers isn't called until the addObserver method is called. When is the Word.addObserver method called from GameController and why are observers notified?

  6. The Word object used in GameController.playGame is observed by the GameController's WordDisplay object. When is the word printed (with letters and blanks shown)?

  7. Explain the logic behind the code below that adds a part to the Gallows object. boolean alphUsed = myAlphabet.doGuess(s.charAt(0)); if (! w.doGuess(s.charAt(0)) && alphUsed) { myGallows.addPart(); }

  8. The Gallows.display method is called explicitly when the game is played in the body of the while loop of GameController.playgame. Would it be better of the Gallows class notified an observer that the misses had been updated? What object would observe the Gallows class and who should call Gallows.addPart?

Owen L. Astrachan
Last modified: Fri Oct 27 10:10:22 EDT 2000