Wheel of Fortune

Overview

Implement a text-based version of the classic game show Wheel of Fortune. One player attempts to solve a hidden phrase by guessing letters. The game includes a spinning wheel with monetary values, a puzzle board, and a high-score system saved to a file.

Puzzle

You must implement the Puzzle class is described in the UML class diagram below. This class describes the state of the game.

  • You may add additional helper methods.
  • You must not add instance variables.
  • You must include a class specification for Puzzle. The specification will include a class invariant (given as a comment at the top of the class) and a method specification for each method (given as comments immediately prior to each method).
Puzzle
-String phrase
// The full secret phrase (uppercase, no punctuation).
-char[] displayed
// Current board state: revealed letters or '_'.
-boolean[] guessed
// Index i true if letter 'A'+i has been guessed.
+Puzzle(String phrase)
// Constructor. Initializes displayed with '_' for letters, spaces preserved.
+boolean guessLetter(char letter)
// Returns true if letter appears in phrase and was not previously guessed. Updates displayed.
+boolean isSolved()
// Returns true if all letters in phrase are revealed.
+String getDisplayed()
// Returns current board as String (e.g., "_ _ E E _")
+int countOccurrences(char letter)
// Returns number of times letter appears in phrase (case-insensitive).
+String getPhrase()
// Returns full phrase (only for end of game).

Wheel

The Wheel class simulates the spinning wheel with monetary values and one special outcomes. You must implement the UML class diagram below.

  • You may add additional methods.
  • You must not add instance variables.
  • You must include a class specification for the Wheel. The specification will include a class invariant and method specifications.
Wheel
-int[] values
// Array of possible outcomes that includes: six 500s, five 600s, four 800s, three 900s, two 1000s, one 5000 and one -1.
+Wheel()
+int spin()
// Returns a random value from the wheel.

Score

The Score class represents the players current winnings.

Score
-String playerName
-int winnings
+Score(String name, int winnings)
+updateBy(int amount)
// increase winning by amount if amount is positive. Otherwise set winnings to zero (the bankrupt outcome).
+String toString()
// Human-readable format

WheelOfFortuneGame

Write a program named WheelOfFortuneGame. This class must not have any instance variables! You may write any static helper methods. The main method must not have a throws clause. The game must:

  • Load puzzles from a puzzle file. A puzzle file is a text file. The first line of a puzzle file has a single integer number denoting the number of puzzles in the file. Each subsequent line has one phrase in all uppercase characters. The name of the file is given as the first command-line argument.
  • Load scores from a scores file. A scores file is a text file. The first line of scores file has an integer number denoting the number of scores in the file. Each following line has a score consisting of a player name followed by a single space followed by an integer number denoting their winnings. The name of the file is given as the second command-line argument.
  • The program must a) select a puzzle at random b) print a menu c) update the game with each selection and d) when the game exits, it must save the updated scores to the same scores file that was loaded.
  • Use selection sort to know what the top 5 scores are.

The game is played by either spinning the wheel, buying a vowel or attempting to solve the puzzle. When a player spins the wheel, they obtain a value N. They then guess a non-vowel that hasn't already been chosen. If we let the value K denote the number of occurrences of that guess in the puzzle, the player is awarded $(N*K) in their account and those occurrences are revealed in the puzzle. If the player has at least $250 in their winnings, they are able to buy a vowel. Their winnings are reduced by $250 and they may choose a vowel that hasn't already been chosen. Each occurrence of the chosen vowel is then displayed but the player gains no winnings. If the player chooses to solve the puzzle, the must enter the entire phrase. If the phrase matches the puzzle (using a case insensitive comparison), the game is over.

=== WHEEL OF FORTUNE ===
1. Spin the Wheel
2. Buy a vowel
3. Solve the Puzzle
4. Quit
Enter choice: 1
*SPINNING* ... $600!
Guess a letter: T
'T' appears 3 times! +$1800
Current winnings: $1800

T _ _  _ _ _T  T_ _ _ _ _  _ _  _ _ _ _

1. Spin the Wheel
2. Buy a vowel
3. Solve the Puzzle
4. Quit
Enter choice: 2
Buy which vowel (costs $250): E
'E' appears 2 times!
Current winnings: $1550

T _ E  _ E _T  T_ _ _ _ _  _ _  _ _ _ E

1. Spin the Wheel
2. Buy a vowel
3. Solve the Puzzle
4. Quit
Enter choice: 3
Enter your solution: THE BEST THINGS IN LIFE
Correct! You solved it!

=== FINAL WINNINGS: $1550 ===
Enter your name: Morgan

=== TOP 5 HIGH SCORES ===
1. Jordan   - $5200
2. Alex     - $2100
3. Taylor   - $1800
4. Morgan   - $1550
5. Casey    - $900

Play again? (y/n): n
Goodbye!

Example files

Submission

Email all *.java files.