Sunday 31 October 2010

Chapter 5 TEST

Part 1:


a&b) I have read the clients specifications and I believe I have a clear understanding of the clients requirements.
I am suppose to create a word guessing game in which a word is randomly chosen and the objective is to figure out the chosen word. The user will be given the length of the word and will have to input words of the same length to discover the word. After inputing a word the user will be told how many letters were correct.  Ex: if the word is PIG and the user puts in POT the output will show 1. In order to quit ot give up the user must type x for every character of the word.Ex: if the word is MAN the user must input XXX.

c) To make this we must have a Responder class which generates a response according to the users input. The responder class represents a response generator object. It is used to generate an automatic response. Since we must read the users input in order to respond, we must also create an InputReader Class. InputReader reads typed text input from the standard text terminal. The text typed by a user is then dividedinto words, and a set of words is provided. We also need a class called WordGuessingGame which implements and puts to use the other classe in order to create the game.

public class WordGuessingGame:

/** This class is implements a Word Guessing Game. The game communicates with the user via input/output messages in the terminal window.
*
* This class uses an object of class InputReader to read input from the user, and an
* object of class Responder to generate responses. It repeatedly
* reads input and generates output until the users wants to leave.


@ version 1.0
@author Jonathan The Beast Schory


public class Responder:



/**
 * The responder class represents a response generator object.
 * It is used to generate an response according to the InputReader class. the response will be generated according to the requirements listed in section a&b.
 * 
 * @author     Jonathan The Beast Schory
 * @version    1.0
 */




public class InputReader:

/**
 * InputReader reads typed text input from the standard text terminal. 
 * the reader will test the input and respond to it according to the requirements listed in section a&b.
 * 
 * @author     Jonathan The Beast Schory
 * @version    1.0
 */




public class InputReader




Part 2:



Discuss (in your blog) the possible uses of each of the following classes in the implementation of the project. You can refer to the class documentation at the Duke site for details of the classes.

a. HashMap

containsKey

public boolean containsKey(java.lang.Object key)

Description copied from interface: Map
Returns true if there is a value associated with key in this map, otherwise returns false.
Specified by:
containsKey in interface Map

Parameters:
key - is the key for which the map is queried as to the existence of an associated value
Returns:
true if there is a (key,value) pair in the map for the specified key, otherwise return false
Perhaps we can use hashmap to determine if the input contains characters from the word the user needs to guess.
*** I am still having trouble clearly understanding the methods and the independent use of hashmaps. Please talk to me next class so we can discuss and you could clarify some of my confusions.***



b. Random

the random class must be used in this project in order to generate a random word which the user must guess. 
For example:
Text File: "There was a young man from Gondwana, who developed a severe case of Pangea, try as he would, he never quite could, find his way back to good old Gondwana."
Word chosen at random (#5) man

c. HashSet

d String
Very important for this project since the whole game is based on guessing a certain word(string) by inputing other words(strings) in the input. We use strings and test them to determine how many characters of the users input are correct. We also use strings for the whole communication with the user. A welcome or Goodbye message are actually strings.



No comments:

Post a Comment