Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 5: Game Wheel For this assignment, you will simulate spinning a Game Wheel with 40 designated spots, each marked with an ID number, color,

Assignment 5: Game Wheel

For this assignment, you will simulate spinning a Game Wheel with 40 designated spots, each marked with an ID number, color, and cash prize amount. To help envision this Game Wheel, imagine a circular pie, with 40 evenly cut slices. Each slice is called a Prize Card (for the purposes of this assignment), and contains an ID number, color, and cash prize amount.

Click here (Links to an external site.)Links to an external site. to download the starter files for this assignment. The Java class PrizeCard has been completed and provided to you. You do not need to modify PrizeCard.java.

Class GameWheel

The first class you will be working on is GameWheel. To help represent this wheel, an ArrayList of PrizeCard objects will be used in the GameWheel class. When initialized, the first PrizeCard in the ArrayList will have an ID #1, the second will have ID #2, and so on. A Prize Card with an odd ID # will be the color red, and a Prize Card with an even ID # will be the color blue, except if the ID # is a multiple of 10, in which case it will be the color black.

Please download the starting template, GameWheel.java. You will need to implement the following method:

public ArrayList scramble() - This method will scramble the ordering of the Prize Cards in the Game Wheel. Be careful, because the pattern of the coloring must be maintained (i.e. the first Prize Card should still be a card that is red, but likely a different ID number and prize amount, the second Prize Card should still be a card that is blue, the tenth Prize Card should still be black). In other words, once a color is assigned to a Prize Card, it does not change; when the wheel is scrambled, it is only putting cards that are already red in the places where red cards belong (odd numbered places), black cards where black cards belong (multiples of 10), and blue cards where blue cards belong (even numbered places).

For a simplified example, lets think about the Prize Cards by just their ID numbers. Lets say we have a Game Wheel with 10 Prize Cards, initially in the order [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. After calling scramble(), the order could possibly now be [7, 4, 3, 6, 9, 2, 5, 8, 1, 10]. Notice the pattern is still red (odd ID), blue (even ID), red, blue, red, blue, red, blue, red, black (ID is multiple of 10).

Please refer to the specification above for how the colors were determined. (Hint: Remember that the coloring is determined by some specific characteristic of the Prize Card ID. Also, dont be afraid to create temporary ArrayLists to help complete the work.) The newly scrambled wheel should then be returned.

Class Main

The second class you will be working on will be the Main class. Main should have a main method. Here, you will utilize the PrizeCard and GameWheel classes to simulate two players who will spin the wheel. The first player will get to spin 5 consecutive times. Then the second player will get to spin 5 consecutive times.

If either players spin results in a Prize Card they have already landed on, the player will ignore that spin and spin again. Thus, when a player is done spinning, the player should have 5 unique prize cards.

In order to simulate a spin of the wheel, use GameWheels method spinWheel() which is already implemented for you. The method spinWheel() will return a PrizeCard object, the PrizeCard that the spin landed on.

At the end the total cash prize amount for the first player should be calculated then printed out. Following the total amount, the Prize Cards that the players spins landed on should also be printed out using PrizeCards toString() method. For example, in the Sample Run below, Player 1s five spins landed on Prize Cards with ID # 21, 4, 6, 11, 27.

The same should then be done for the second player.

At the very end, the players total cash prize amounts should be compared to one another, and a statement should be printed out indicating which player won more money, as well as how much more money that player won by. If the result is a tie, the output should simply say "Its a tie!"

Final Notes

Remember, all variables should have an access level of private and all required methods should have an access level of public.

There is no Student Runner File for this assignment. To test your code, run the Main.java file in DrJava and verify that the class output matches the Sample Run pattern that follows. Since the assignment involves an element of randomized results, your own results will vary from the sample run. However, note that neither player has a repeated spin result. We will use our own runner to grade the program.

When you are ready, follow the links below to submit your entire GameWheel and Main classes separately. You must submit both, and you must paste your entire class into the appropriate boxes (including all methods that were implemented for you). Each class is worth 5 points, out of a total of 10.

Sample run #1 of Main.java:

Player 1 Total: $1590 ID: 21, Color: red, Prize Amount: $210 ID: 4, Color: blue, Prize Amount: $400 ID: 6, Color: blue, Prize Amount: $600 ID: 11, Color: red, Prize Amount: $110 ID: 27, Color: red, Prize Amount: $270 Player 2 Total: $9390 ID: 19, Color: red, Prize Amount: $190 ID: 34, Color: blue, Prize Amount: $3400 ID: 18, Color: blue, Prize Amount: $1800 ID: 12, Color: blue, Prize Amount: $1200 ID: 28, Color: blue, Prize Amount: $2800 Player 2 won by $7800! 

Sample run #2 of Main.java:

Player 1 Total: $7170 ID: 20, Color: black, Prize Amount: $4000 ID: 26, Color: blue, Prize Amount: $2600 ID: 37, Color: red, Prize Amount: $370 ID: 15, Color: red, Prize Amount: $150 ID: 5, Color: red, Prize Amount: $50 Player 2 Total: $1340 ID: 29, Color: red, Prize Amount: $290 ID: 23, Color: red, Prize Amount: $230 ID: 3, Color: red, Prize Amount: $30 ID: 39, Color: red, Prize Amount: $390 ID: 4, Color: blue, Prize Amount: $400 Player 1 won by $5830! 

Starter Files:

GameWheel Class:

import java.util.*; import java.lang.*; public class GameWheel { private ArrayList prizeCards; private int currentPos; public GameWheel() { prizeCards = new ArrayList(); currentPos = 0; prizeCards = initGameWheel(); prizeCards = scramble(); } public ArrayList initGameWheel() { ArrayList init = new ArrayList(); for (int i=1; i <= 40; i++) { if (i%2 == 1) init.add(new PrizeCard(i, "red", i*10)); else if (i%10 == 0) init.add(new PrizeCard(i, "black", i*200)); else init.add(new PrizeCard(i, "blue", i*100)); } return init; } public ArrayList getPrizeCards() { return prizeCards; } public ArrayList scramble() { // This method will scramble the ordering of the Prize Cards in the Game Wheel. Be careful, because // the pattern of the coloring must be maintained (i.e. the first Prize Card should still be a card // that is red, but likely a different ID number and prize amount, the second Prize Card should // still be a card that is blue, the tenth Prize Card should still be black). In other words, once // a color is assigned to a Prize Card, it does not change; when the wheel is scrambled, it is only // putting cards that are already red in the places where red cards belong (odd numbered places), // black cards where black cards belong (multiples of 10), and blue cards where blue cards belong // (even numberedplaces). ArrayList scrambled = new ArrayList(); /* write your code here */ return scrambled; } public PrizeCard spinWheel() { //spin power between range of 1-100 (inclusive) int power = (int)(Math.random()*100 + 1); int newPos = (currentPos + power) % prizeCards.size(); currentPos = newPos; return prizeCards.get(currentPos); } } 
 public class PrizeCard { private int id; private String color; private int prizeAmount; public PrizeCard() { id = 0; color = "red"; prizeAmount = 0; } public PrizeCard(int nID, String nColor, int nPrizeAmount) { id = nID; color = nColor; prizeAmount = nPrizeAmount; } public int getID() { return id; } public int getPrizeAmount() { return prizeAmount; } public String toString() { return "ID: " + id + ", Color: " + color + ", Prize Amount: $" + prizeAmount; } } 

Main Class:

import java.util.*; public class Main { public static void main (String[] args) { // Write your code here } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions