0% found this document useful (0 votes)
62 views

COMSATS Institute of Information Technology,: Submission Deadline 4 May 2016

The document describes an assignment to create a word guessing game called Words_Guesser using Java. The program will randomly select a word from an array of words and prompt the user to guess letters. If correct, revealed letters are displayed. If incorrect, remaining tries are shown. The goal is to guess the word before reaching 0 tries. The user can then choose to play again or quit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

COMSATS Institute of Information Technology,: Submission Deadline 4 May 2016

The document describes an assignment to create a word guessing game called Words_Guesser using Java. The program will randomly select a word from an array of words and prompt the user to guess letters. If correct, revealed letters are displayed. If incorrect, remaining tries are shown. The goal is to guess the word before reaching 0 tries. The user can then choose to play again or quit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

COMSATS Institute of Information Technology, Abbottabad.

Assignment Number 2

Subject: Object Oriented Programming.


Instructor: Mr. Fuzel Jamil Submission Deadline 4 May 2016

In this assignment you are required to develop an interactive and fun game named Words_Guesser using java. The Game works as
follows:

The Program randomly chooses a word from an Array that contains some words of different lengths and the player has to guess it.
It also selects a guess limit and informs the user respectively. The unguessed letters within the chosen word are represented as a
sequence of asterisk characters, one per letter. The User is then prompted to guess the chosen word letter by letter. If a letter that is
found within the chosen word, all the asterisks representing the letter are replaced and the partially guessed word is displayed to the
user. If the letter is not part of the chosen word, a message is displayed showing the remaining tries and all the wrong alphabets
guessed. If a correct guess is made within the limit the user wins, otherwise he loses the game. The user is displayed a message
informing him of the number of guesses used and tries left (if any). The user is then prompted if he wants to play the game again or
quit.

 Use an array called "wordsList" of type String to store 10 words (minimum). These words can be any names of
your choice i.e. countries, name of cartoon characters, famous artists, singers, scientists and so on.
o You should prompt/inform the user to guess the word.
 Rules of the Game:
o Winning the game: A player can win the game if she/guessed the word correctly within the permitted
tries limit allowed for each player per game.
o The words should be selected at random by the program from the "wordsList" array.
o Losing the Game: A player loses the game and game will be over if the user didn't guess the word
after limit tries.
o Results: Your program should keep track of the result (number of guesses during the game) and
number of tries left if any.

Hints:

Keep your design simple and consistent throughout the game.

 Use a math.random() to select the questions from the "wordsList" array.


 Track the guessed word, no of total guesses and tries in separate variables
 Update the guessed word on correct letter guesses
 Use user-defined methods to model your program and make it efficient.
 When comparing two strings to test for equality, do not use "==" operator.
 Handle casing, either convert case or ignore it.
The following is a sample run of the game for your understanding.

Welcome to the Words_Guesser game Designed by (Insert Name and Reg number here), good Luck

We have chosen a word…..Guess it!!!!


You have 5 tries. (Lets assume the system chooses the word “comsats”)

The word is *******


Guess number 1: z
The word does not contain the letter z !!!
You have 4 tries left!!! Wrong guesses include: z
Try again:
Guess number 2: s
Yes the word does contain the letter s !!!
The word is: ***s**s Continue: (the letter s is displayed in its respective positions)
Guess number 3: t
Yes the word does contain the letter t !!!
The word is: ***s*ts Continue: (the letter t is displayed in its respective positions)
Guess number 4: k
The word does not contain the letter k !!!
You have 3 tries left!!! Wrong guesses include: z k
Try again:
Guess number 5: c
Yes the word does contain the letter c !!!
The word is: c**s*ts Continue: (the letter c is displayed in its respective positions)
Guess number 6: b
The word does not contain the letter b !!!
You have 2 tries left!!! Wrong guesses include: z k b
Try again:
Guess number 7: o
Yes the word does contain the letter o !!!
The word is: co*s*ts Continue: (the letter o is displayed in its respective positions)
Guess number 8: a
Yes the word does contain the letter a !!!
The word is: co*sats Continue: (the letter a is displayed in its respective positions)
Guess number 9: m
Yes the word does contain the letter m !!!
Congratulations, you guessed the word comsats correctly in 9 attempts with 2 tries left!!
Do you want to play again? :

You might also like