You are on page 1of 9

While-Do while- For

Activity 6-
Guesser Game

Mariangelly Saray Garcia Gomez


What does the program use the while
statement for?
The program uses the while instruction to create a loop that allows the player
to try to guess a magic number where he has a limited number of attempts.

How do you exit the while statement?


We can leave the "While" instruction in two ways, the player must guess the
magic number or the player uses all his attempts and does not guess the
number. Only if one of these two conditions is met can you leave the while
instruction.
What value does the variable played at the
end of the cycle reach?
The variable played made at the end of the cycle will have the value of the
number of attempts made by the player, either less than 10 or equal to 10,
which is the limit of attempts that are made.

After how many moves at most can the player


find the magic number?
The moves that the player can make to guess the magic number are 10, since
the value of the number played is declared with the constant 10.
Explain the input data, why are some constant?
In the input data we find:

• String nombreJugador: The name of the player, entered by the player.


• final byte númeroJugadas=(byte)10: Represents the maximum number of attempts
that the player has to guess the magic number and since it is declared as a constant,
there will always be only 10 attempts allowed.
• byte numeroX: This variable stores the number that the player enters on each
attempt.
• final byte minimo=1: Represents the minimum possible value that the magic number
can have, just like “number of Plays” this is declared as a constant so the minimum
value will always be 1.
• Byte maximo: Represents the maximum possible value that the magic number can have,
this value is given by the player.

Some of this data is constant because, since it is already declared, it does not change
once it is established.
Why do you think the constants are used in the
definition of line 7 and line 9?
In these lines, constants are used to declare values that should not change in
the program. The variable numeroJugadas is set to 10 to limit the number of
player attempts, and minimum is set to 1 to set the minimum value for the
magic number.
Explain lines 34 to 35
Lines 34 and 35 are part of the create NumeroMagico method in the Riddle
class. These lines create a random magic number within the specific range.
From line 34 to 35, suppose that the maximum=100 and
minimum=200, what possible values would Magic
number have?
From line 34 to 35, suppose that the maximum=90 and
minimum=110, what possible values would the magic
number have?
In these two cases there are no possible valid values for the magic
number, since maximum must be greater than minimum, possible values
could not be generated for magic number.
How would you cheat on the game? What
instructions would you put in the code to perform
the trap?
I would cheat the game by modifying the code, I would remove the else where it
gives the indication that the number is incorrect and thus I would win.

You might also like