ITEC 120
HW5: Wheel of Fortune methods

Academic Integrity

Be reminded that this homework assignment must be your own work.

Objectives

After successfully completing this lab you will be able to implement methods operating on Strings and arrays of characters.

Assignment

Develop several methods that can be used to build a Wheel of Fortune style word game.

For HW4, you wrote a Wheel of Fortune style game in one main method, around 70 lines of code or more. For this assignment, you will explore a better design. For 85% credit, you will implement 4 methods. For the remaining 15%, you may write a game driver which calls those methods.

A test driver has been written for you: HW5TestDrv.java. Download it, put it in the directory where you will develop your HW5Srv.java, and use it to test your methods as you develop them. Don't change the test driver - a new copy of this test driver will be used to grade your work, so you need to write methods that will pass all of these tests.

The design of this assignment has been done for you. There are certainly other ways to design this game, but, this is a good one, and one that makes good use of methods. Use this design, and think about the advantages this kind of design has over the HW4 approach.

The four methods you will write are: createKey, createPuzzle, isSolved, and checkGuess

createKey

public String createKey(String phrase)

createKey takes a String as a parameter and returns a String based on these rules:

For example:

createKey("Hi Ho!") --> "H I    H O ! "

 

createPuzzle

public char[] createPuzzle(String phrase)

createPuzzle takes a String as a parameter and returns an array of char based on these rules:

For example:

createPuzzle("Ho!") --> ['_',' ','_',' ','!',' ']

 

isSolved

public boolean isSolved(String key, char[] puzzle)

isSolved answers if the puzzle is solved. It takes two parameters, the key (a String) and the puzzle (an array of char). If all the characters in the array are the same as the characters in the String, in the same order, then isSolved returns true. if the length of the given key is not the same as the length of the puzzle, isSolved returns false. if the lengths are the same, and any character is different, isSolved returns false.

 

checkGuess

public void checkGuess(char guess, String key, char[] puzzle)

checkGuess takes a char, the guessed letter, and if that char matches any character in the key, it puts that char into the puzzle array at the same position as the matched char in the key. checkGuess is void, but, the puzzle array may get changed.

For example, if:

puzzle = ['_',' ','_',' ','!',' ']

and the checkGuess method was called:

checkGuess('h',"Ho!",puzzle)

then puzzle would contain:

['H',' ','_',' ','!',' ']

 

GameDrv

For 15% of the grade, implement a game driver that will use the methods you wrote to play a wheel of fortune style game. You will also need to develop one additional method: puzzleString

puzzleString

public String puzzleString(char[] puzzle)

puzzleString takes an array of char and returns a String containing all the characters in the array, appended together, in order. You will find this handy for printing the puzzle in your game driver.

a sample run of the game follows:

Enter a phrase: Westward, Ho!


_ _ _ _ _ _ _ _ , _ _ !

Guess a letter: E

_ E _ _ _ _ _ _ , _ _ !

Guess a letter: s

_ E S _ _ _ _ _ , _ _ !

Guess a letter: t

_ E S T _ _ _ _ , _ _ !

Guess a letter: w

W E S T W _ _ _ , _ _ !

Guess a letter: a

W E S T W A _ _ , _ _ !

Guess a letter: r

W E S T W A R _ , _ _ !

Guess a letter: n

W E S T W A R _ , _ _ !

Guess a letter: o

W E S T W A R _ , _ O !

Guess a letter: h

W E S T W A R _ , H O !

Guess a letter: d

W E S T W A R D , H O !

Hooray! It took you 10 guesses.

 

Submit Your Assignment

Submit your HW5Srv.java, and your GameDriver.java to the HW5 dropbox on D2L.