# Word Scramble Using Objects & Methods

• December 8th, 2009, 03:35 AM
Whitechapel
Word Scramble Using Objects & Methods
Alright, I'm not looking for an EXACT solution (Unless you seriously want to give the time to help me out that much) I'm just looking for where I should start and maybe a really nice detailed algorithm.

I've got an assignment to create a Word Jumble game played between two players. I've got some fairly specific guidelines I need to follow which I will post:

PROBLEM

For this assignment you are to create a simple word guessing game for two players. For each round in the game the following sequence is followed:

first player enters a word to be guessed
the program rearranges the letters in the word and displays to the second player
the second player has 5 attempts to guess the word correctly

second player enters a word to be guessed
the program rearranges the letters in the word and displays to the first player
the first player has 5 attempts to guess the word correctly

The scoring for the game is as follows:
100 points if guessed on first try
80 points if guessed on second try
60 points if guessed on third try
40 points if guessed on fourth try
20 points if guessed on fifth try

The players have the option to play as many rounds as they would like. The game is over when players select “quit program” from the menu.

The program will automatically play the first round. After that a menu will appear to allow the players the option of displaying their score, playing another round, ending the game or quitting the program immediately. The menu will appear as follows:

Please select from one of the following options:
p - play another round
s - display current score
e - end game and display final score
q - quit program

CLASSES

For this problem you are required to create specific classes and methods. The following classes and methods are required.

Player Class
This class maintains information about a player. It has two private attributes, name and score. The following methods are required for this class:

Player( name : String ) Constructor which creates a new instance with name specified.

increaseScore( amount : int ) Method which adds the specified amount to the player’s score.

resetScore( ) Method resets player’s score to zero

getName() Accessor method which returns player’s name

displayScoreDetails() Method which displays the player’s name and score to console output in the form “name: score”.

findWinner( player1 : Player, player2 : Player ) This static method accepts two Player instances and determines which of the players has the higher score. The method returns the Player instance of the player with the highest score. If the players are tied this method returns null as there is no winner.

Word Class
This class maintains information about a word. It has one private attribute, word. The following methods are required:

Word( word : String ) Constructor accepting word to use.

Word() Constructor which uses the default word of “popcorn”. Use constructor chaining.

getWord() This method returns the word.

getJumbledWord() This method returns the word with the letters mixed up. This method must mix up the letters by taking the original word and performing ten letter swaps. This method should have a loop that loops ten times. Each time through the loop randomly pick two letters and swap their positions in the word.
doesWordMatch( otherWord : String ) This method compares the provided word to its word. If the word is an exact match it will return true otherwise it returns false. Note: case is irrelevant so make sure the case is ignored.

Jumble Class

This is the class that plays the game. It makes use of the Player and Word classes. It has three private attributes, player1, player2 and input. The input attribute represents the Scanner instance and is used for getting input from the user. The following methods are required for this class:

main( args : String[] ) Main entry point for the Java application. This method should instantiate the Jumble class and call the playGame method.

Jumble() Constructor. Displays welcome message and creates two new player instances. Use the getPlayerName method to get the two player names.

getPlayerName() This method gets the user to enter a player name. Make sure the player name is at least one character long.

getPlayerGuess( word : Word, player : Player ) This method is responsible for getting a player’s guess for a word. This method should do the following:
- clear the screen by displaying 25 blank lines
- use a loop to allow the player up to five guesses
- ask the player for their guess
- if the guess is correct, add appropriate amount to player’s score. Amount to add is based on which guess it is. First guess is 100 points, second is 80, third is 60, fourth is 40 and fifth is 20. If the player does not guess within five guesses, the player scores nothing.
playGame() This method handles the main loop for playing the game. The loop should loop while the user wants to keep running the program. The first time through the loop, the first round should automatically be played. Within this loop do the appropriate action based on the choice selected by the user. The choices are:
- play a round. Each player gets to provide one word that the other player then guesses. Ask each player to enter a word and use the getPlayerGuess method for having the other player guess the word.
- display the current score for each player. Use the displayScoreDetails method in the Player class.
- end the game and display the final score for each player, including indicating who won the game. Call the displayWinner method in the Jumble class.
- quit the program. Terminate the program. No scores are displayed, and no indication is given of who won the game.
Use the getMenuChoice method to display the menu and get the user choice.

displayWinner() Use the findWinner method in the Player class to determine who is the winner. Use the displayScoreDetails to display the final score for each player. Reset the scores for each player.

getMenuChoice() This method should display the menu and get the user choice. Make sure the input is validated.
• December 8th, 2009, 03:49 AM
Whitechapel
Re: Word Scramble Using Objects & Methods
Also, here is some sample output for the program:
Welcome to Jumble - the mixed up word guessing game
Enter player name
Sharon
Enter player name
Shane
Sharon enter a word. Shane no peeking!
stale

Shane the jumbled word is etasl
least

Sorry, that is not the word.
Please guess again. Jumbled word is etasl
slate

Sorry, that is not the word.
Please guess again. Jumbled word is etasl
stale

Shane enter a word. Sharon no peeking!
grate

Sharon the jumbled word is arget
great

Sorry, that is not the word.
Please guess again. Jumbled word is arget
grate

Please select from one of the following options:
p - play another round
s - display current score
e - end game and display final score
q - quit program
s
Current Score:
Sharon: 80
Shane: 60

Please select from one of the following options:
p - play another round
s - display current score
e - end game and display final score
q - quit program
p
Sharon enter a word. Shane no peeking!
skates

Shane the jumbled word is atskes
steaks

Sorry, that is not the word.
Please guess again. Jumbled word is atskes
skates

Shane enter a word. Sharon no peeking!
lodge

Sharon the jumbled word is egold
lodge

Please select from one of the following options:
p - play another round
s - display current score
e - end game and display final score
q - quit program
e
Congratualtions Sharon you win!
Final Score:
Sharon: 180
Shane: 140

Please select from one of the following options:
p - play another round
s - display current score
e - end game and display final score
q - quit program
s
Current Score:
Sharon: 0
Shane: 0

Please select from one of the following options:
p - play another round
s - display current score
e - end game and display final score
q - quit program
p
Sharon enter a word. Shane no peeking!
popcorn

Shane the jumbled word is noocprp
popcorn

Shane enter a word. Sharon no peeking!
synthesis

Sharon the jumbled word is hitsssyne
hiss

Sorry, that is not the word.
Please guess again. Jumbled word is hitsssyne
stein

Sorry, that is not the word.
Please guess again. Jumbled word is hitsssyne
snitty

Sorry, that is not the word.
Please guess again. Jumbled word is hitsssyne
justfooling

Sorry, that is not the word.
Please guess again. Jumbled word is hitsssyne
noguessthistime

Sorry, that is not the word.
Round over. You scored 0

Please select from one of the following options:
p - play another round
s - display current score
e - end game and display final score
q - quit program
s
Current Score:
Sharon: 0
Shane: 100

Please select from one of the following options:
p - play another round
s - display current score
e - end game and display final score
q - quit program
e
Congratualtions Shane you win!
Final Score:
Sharon: 0
Shane: 100

Please select from one of the following options:
p - play another round
s - display current score
e - end game and display final score
q - quit program
q
• December 10th, 2009, 01:12 AM
Whitechapel
Re: Word Scramble Using Objects & Methods
Problem Solved!
• May 23rd, 2010, 12:38 PM
novice
Re: Word Scramble Using Objects & Methods
I am actually doing this for my notes since I was absent from CS class, but I don't know how to do it, so could you share the code or help me out?