Professional Documents
Culture Documents
1. At the beginning of the Hangman, there are six words that the player must guess. The words are:
i. “terminator”
ii. “banana”
iii. “computer”
iv. “cow”
v. “rain”
vi. “water”
The informal statements are:
private static String[] words = {"terminator", "banana", "computer", "cow", "rain", "water" };
private static String word = words[(int) (Math.random() * words.length)];
private static String asterisk = new String(new char[word.length()]).replace("\0", "*");
Denoted words in array is W
Denoted word as w
Words in array are multiply by Math.random to get the length of the words and become a
new declaration which is w
The formal statements:
∀ w ∈ W | W isMultiply Math.random w
2. After the program select any words in array that the player must guess, it changes each letters of the
words to symbol “*” depends on the word length.
The formal statement:
private static String asterisk = new String(new char[word.length()]).replace("\0", "*");
Denoted asterisk as A
Denoted char as C
The informal statement:
∀ A ∈ w, C ∈ A | C(w.length()) isReplace(“\0”, “*”) *
3. Player will guess letter by letter until they get the correct words.
The informal statement:
for (int i = 0; i < word.length(); i++)
{
if (word.charAt(i) == guess.charAt(0))
{
newasterisk += guess.charAt(0);
}
else if (asterisk.charAt(i) != '*')
{
newasterisk += word.charAt(i);
}
else
{
newasterisk += "*";
}
}
4. If the player got one wrong letter, the hangman image will appear little by little until 7 trial of
guessing the word.
The formal statement:
if (asterisk.equals(newasterisk))
{
count++;
hangmanImage();
}
Denoted newasterisk as a
The informal statement:
A ∈ a count++, display hangmanImage(count == 1)