Question
Assignment 7: Game Wheel Instructions For this assignment, you will work on a multi-file program which represents a game using a spinnable Game Wheel, a
Assignment 7: Game Wheel
Instructions
For this assignment, you will work on a multi-file program which represents a game using a spinnable Game Wheel, a bit like the one seen on the show Wheel Of Fortune (below).
Your Game Wheel will have 20 evenly cut colored slices, each marked with a cash prize amount. Two classes are used to create this wheel: GameWheel and Slice. You will not need to edit the Slice class, but you will implement some of the methods for the GameWheel class. You will also write a method in a third class named Game which can be used to play the game.
As this assignment uses pre-written methods which you will need to use in your code, brief documentation of the constructors and public methods of the GameWheel and Slice classes is included at the end of the assignment brief.
Part 1: GameWheel
When a new GameWheel is created it always contains 20 slices, which are represented in the GameWheel class by an ArrayList of Slice objects. The wheel is initialized so that every slice with an odd index is red and every slice with an even index is blue, with the exception of the slices at positions 0, 5, 10 and 15 which are all black. Every slice is initialized with a different prize value.
You will implement three different public methods in the GameWheel class.
toString
The first of these methods is the toString method, which returns a String consisting of a numbered list of all slices of GameWheel (using the slice toString method), one on each line. This should be in the format shown below:
0 - Color: black, Prize Amount: $4000 1 - Color: red, Prize Amount: $10 2 - Color: blue, Prize Amount: $200 3 - Color: red, Prize Amount: $30 ... 19 - Color: red, Prize Amount: $190
You may find the toString method helpful when testing your other GameWheel methods.
scramble
The second method you will write is the scramble method, which randomizes the positions of the slices that are in the wheel, but without changing the pattern of the colors (i.e. the black slices will still be at multiples of 5, the red slices at all other odd indices and the blue slices at all other even indices). No individual slice should be changed, rather the slices should be re-ordered.
sort
The third method to implement is the sort method. This is similar to the scramble method in that it reorders the slices in the GameWheel so that the pattern of the colors remains the same. After the sort method is called however the slices of each color should be sorted in increasing order of prize amount. So for example the black slice with the lowest prize value will be at index 0, and the black slice with the highest prize value will be at index 15.
Part 2: Game/play
When you have done the above, you will write a method in the Game class named play. This method has a single GameWheel parameter. When run, this method will simulate a game in which the game wheel represented by this parameter is spun three times and the results are used to calculate a total prize. The total prize is found by adding the values on the three slices. If all three slices are the same color, then this sum should be doubled (and an additional line should be printed at the end explaining this). For the exact format of the output of the program, see the sample runs below (as this program involves some randomization the actual output will vary).
Sample run 1
Total prize money: $7000 Spin 1 - Color: black, Prize Amount: $4000 Spin 2 - Color: blue, Prize Amount: $2400 Spin 3 - Color: blue, Prize Amount: $600
Sample run 2
Total prize money: $820 Spin 1 - Color: red, Prize Amount: $50 Spin 2 - Color: red, Prize Amount: $130 Spin 3 - Color: red, Prize Amount: $230 Three reds = double your money!
Testing your code
The fourth class named Runner has a pre-written main method which will let you test your code. You can choose to play the game by calling the play method from your game class or test individual methods from the GameWheel class. Please do not write a main method in any of the other classes as these will stop your code from being scored correctly.
Documentation
Slice class | |
Slice(String c, int p) | Creates a slice with color c, and cash prize p. |
int getPrizeAmount() | Returns the cash prize in dollars for this slice. |
String getColor() | Returns the color of this slice as a string. |
String toString() | Returns a string representation of the slice in the following format: Color: red, Prize amount: $50. |
GameWheel class | |
GameWheel() | Creates a wheel with 20 slices with preset prize amounts. |
GameWheel(int[] prizes) | Creates a wheel with the prize amounts given in the prizes array. |
Slice spinWheel() | Spins the wheel so that a different slice is selected. Return that slice (Note: the 10 slices following the current slice are more likely to be returned than the other 10). |
Milestones
As you work on this assignment, you can use the milestones below to inform your development process:
Milestone 1: Set up the toString method for the gameWheel class so you can test your methods as you write them. Plan how you will decompose the scramble and sort methods (i.e. are there helper methods which can be used by both).
Milestone 2: Write the scramble and sort methods in the gameWheel class. Use the runner class and the toString methods to test these methods work exactly as intended.
Milestone 3: Implement the play method in the game class. Make sure you run this multiple times to ensure it works under a variety of conditions.
Decomposition hints
More than any exercise or assignment you've seen so far, this assignment requires you to carefully decompose what needs to be done into steps. This is especially true when implementing the scramble and sort methods. There is no one right way to do this, and very different approaches can still end up working. Below are some hints which might help you get started, but do feel free to experiment and come up with your own way
- One way to implement the scramble and sort methods might be to split the slices list up into separate lists by color, then put them back together into the slices list once they are scrambled/sorted.
- You could sort/scramble these separate lists, or be even smarter and sort/scramble them either as you put them into the list or as you put them back into slices.
- Because there is a lot of repetition in these methods you should think about writing helper methods that prevent you from having to write code which is almost the same several times.
- Examples of where helper methods could be useful include splitting slices into lists by color, sorting a list, scrambling a list, and recombining separate lists to make a new slices list.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started