You are on page 1of 4

Formal Statement

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)

5. The hangman image is depending on count


Formal statement:
if (count == 1) {
System.out.println("Wrong guess, try again");
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println("___|___");
System.out.println();
}
if (count == 2) {
System.out.println("Wrong guess, try again");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println("___|___");
}
if (count == 3) {
System.out.println("Wrong guess, try again");
System.out.println(" ____________");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" | ");
System.out.println("___|___");
}
if (count == 4) {
System.out.println("Wrong guess, try again");
System.out.println(" ____________");
System.out.println(" | _|_");
System.out.println(" | / \\");
System.out.println(" | | |");
System.out.println(" | \\_ _/");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println("___|___");
}
if (count == 5) {
System.out.println("Wrong guess, try again");
System.out.println(" ____________");
System.out.println(" | _|_");
System.out.println(" | / \\");
System.out.println(" | | |");
System.out.println(" | \\_ _/");
System.out.println(" | |");
System.out.println(" | |");
System.out.println(" |");
System.out.println("___|___");
}
if (count == 6) {
System.out.println("Wrong guess, try again");
System.out.println(" ____________");
System.out.println(" | _|_");
System.out.println(" | / \\");
System.out.println(" | | |");
System.out.println(" | \\_ _/");
System.out.println(" | |");
System.out.println(" | |");
System.out.println(" | / \\ ");
System.out.println("___|___ / \\");
}
if (count == 7) {
System.out.println("GAME OVER!");
System.out.println(" ____________");
System.out.println(" | _|_");
System.out.println(" | / \\");
System.out.println(" | | |");
System.out.println(" | \\_ _/");
System.out.println(" | _|_");
System.out.println(" | / | \\");
System.out.println(" | / \\ ");
System.out.println("___|___ / \\");
System.out.println("GAME OVER! The word was " + word);
}
 Denoted count as O
The informal statement:
 O ∈ w | O isCount++  display hangmanImage

You might also like