Question

In: Computer Science

Question: you will be making a game called “Snap, Crackle, Pop”, a game typically played with...

Question: you will be making a game called “Snap, Crackle, Pop”, a game typically played with a group of 3 persons. Each person chooses one number and it is assigned to either 'snap', 'crackle', or 'pop'. Then the number of rounds is decided (e.g. 12). The players play the game for the predetermined number of rounds (here 12). In each round:

● if the number of the round is a multiple of the snap number, the person who chose the number will say 'snap' instead of the number of the round.

● if it is a multiple of the crackle number, they will say 'crackle' instead.

● if it is a multiple of the pop number, they will say 'pop' instead.

● if it is any combination of the three, they will say 'snapcrackle', 'snappop', 'cracklepop', or 'snapcracklepop' instead of the number of the round, depending on which of the snap, crackle, and pop numbers the current number of the round is a multiple of.

● if the number is not a multiple of snap, crackle, or pop, then the number of the round is said instead.

code to edit:

//TODOa complete this javadoc comment
/**
* [The class description]
* @author [Your Name]
* @version 1.0
*/

//TODO1: declare the SnapCracklePop class

//TODOb Complete Comments
/**
* [Instance Variable Descriptions]
*/

//TODO2 Declare private instance variables
//to store Snap, Crackle, and Pop values


//TODOc complete comments
/**
* [Constructor Description]
* @param [param name] [what the param represents]
* @param [param name] [what the param represents]
* @param [param name] [what the param represents]
*/
  
/* The constructor takes in three ints,
* which must be assigned to their instance variables and initialized.
*/

//TODO3 Write the constructor


//TODOe complete comments
/**
* [Method Description]
* @param [param name] [What the parameter represents]
* @return [What the method returns]
*/

/* playRound() is a helper method for playGame().
* It takes an int parameter representing the
* current round of play, and returns the
* String result for that specific round only.
*/

//TODO4 implement the playRound method


//TODOd complete comments
/**
* [Method Description]
* @param [param name] [What the parameter represents]
* @return [What the method returns]
*/

/* playGame() takes a single parameter representing the rounds and returns
* a String representing the result of the entire game. The helper method
* playRound() may be useful here, so you may want to complete it first.
*/

//TODO5 implement the playGame method
  
//Loop through the rounds of the game
//call playRound to handle the specific round
//return the total aggregated game results

//TODOf complete comments
/**
* [Method Description]
* @return [What this method returns]
*/

//TODO6 implement the getSnap method

//TODOg complete comments
/**
* [Method Description]
* @return [What this method returns]
*/

//TODO7 implement the getCrackle method

//TODOh complete comments
/**
* [Method Description]
* @return [What this method returns]
*/

//TODO8 implement the getPop method

//end class

code not to edit:

import java.util.*;

public class SnapCracklePopMain{

public static void main(String[] args){
  
// The scanner we will be using to accept user input
Scanner scan = new Scanner(System.in);
/* Initializing snap, crackle, pop, and round to invalid values to cause them
* to enter their respective User Input loops.
*/
int snap = -1;
int crackle = -1;
int pop = -1;
int rounds = -1;
  
// Our SnapCracklePop object
SnapCracklePop scp;
  
// Capture user input for snap, while also ensuring correctness
System.out.println("Enter an integer for your snap number.");
while(snap < 0){
System.out.println("Please enter a number greater than zero:");
try{
snap = Integer.parseInt(scan.nextLine());
} catch (Exception e) {
System.out.println("That is not a valid number. Please enter an integer greater than zero.");
}
}
  
// Capture user input for crackle, while also ensuring correctness
System.out.println("Enter an integer for your crackle number.");
while(crackle < 0){
System.out.println("Please enter a number greater than zero:");
try{
crackle = Integer.parseInt(scan.nextLine());
} catch(Exception e) {
System.out.println("That is not a valid number. Please enter an integer greater than zero.");
}
}
  
// Capture user input for pop, while also ensuring correctness
System.out.println("Enter an integer for your pop number.");
while(pop < 0){
System.out.println("Please enter a number greater than zero:");
try{
pop = Integer.parseInt(scan.nextLine());
} catch(Exception e) {
System.out.println("That is not a valid number. Please enter an integer greater than zero.");
}
}
  
// Initializing our SnapCracklePop object with the values we just obtained from the user
scp = new SnapCracklePop(snap, crackle, pop);
  
// Capture user input for rounds, while also ensuring correctness
System.out.println("How many rounds would you like to play?");
while(rounds < 0){
System.out.println("Please enter a number greater than zero:");
try{
rounds = Integer.parseInt(scan.nextLine());
} catch(Exception e) {
System.out.println("That is not a valid number. Please enter an integer greater than zero.");
}
}
  
// Printing results
System.out.println("Results:");
System.out.println(scp.playGame(rounds));

}

}

Solutions

Expert Solution

Code to Copy:

//TODOa complete this javadoc comment
/**
* [The class description]
* @author [Your Name]
* @version 1.0
*/

import java.util.*;

//TODO1: declare the SnapCracklePop class
class SnapCracklePop
{
//TODOb Complete Comments
/**
* [private variables snap, crackle and pop]
*/

//TODO2 Declare private instance variables
//to store Snap, Crackle, and Pop values
private int snap;
private int crackle;
private int pop;

//TODOc complete comments
/**
* [SnapCracklePop]
* @param [snap] [store the integer value of snap]
* @param [crackle] [store the integer value of crackle]
* @param [pop] [store the integer value of pop]
*/
  
/* The constructor takes in three ints,
* which must be assigned to their instance variables and initialized.
*/

//TODO3 Write the constructor
public SnapCracklePop(int snap, int crackle, int pop)
{
this.snap = snap;
this.crackle = crackle;
this.pop = pop;
}

//TODOe complete comments
/**
* [playRound]
* @param [round] [The integer value of current round]
* @return [returns the result of current round]
*/

/* playRound() is a helper method for playGame().
* It takes an int parameter representing the
* current round of play, and returns the
* String result for that specific round only.
*/

//TODO4 implement the playRound method
String playRound(int round)
{
//set the string to empty
String output = "";
//if the current round number is multiple of snap
if(round % this.snap == 0)
{
output += "snap";
}
//if the current round number is multiple of crackle
if(round % this.crackle == 0)
{
output += "crackle";
}
//if the current round number is multiple of pop
if(round % this.pop == 0)
{
output += "pop";
}
//if the output is empty
if(output == "")
{
output += round;
}
return output;
}

//TODOd complete comments
/**
* [playGame]
* @param [rounds] [integer value of number of rounds]
* @return [returns the result of the game]
*/

/* playGame() takes a single parameter representing the rounds and returns
* a String representing the result of the entire game. The helper method
* playRound() may be useful here, so you may want to complete it first.
*/

//TODO5 implement the playGame method
String playGame(int rounds)
{
//set the result to empty string
String result = "";
//set the number of snaps to 0
int snaps = 0;
//set the number of crackles to 0
int crackles = 0;
//set the number of pops to 0
int pops = 0;
//iterate over the rounds
for(int i = 1;i <= rounds;i++)
{
//call the play round function
String current_result = playRound(i);
//if the current result string has snap in it
if(current_result.indexOf("snap") != -1)
{
//increment snaps
snaps++;
}
//if the current result string has crackle in it
if(current_result.indexOf("crackle") != -1)
{
//increment crackles
crackles++;
}
//if the current result string has pop in it
if(current_result.indexOf("pop") != -1)
{
//increment pops
pops++;
}
result += "Round " + i + ": " + current_result + "\n";
}
//add the values to the result with description
result += "Number of Snaps: " + snaps + "\n";
result += "Number of Crackles: " + crackles + "\n";
result += "Number of Pops: " + pops + "\n";
return result;
}
//Loop through the rounds of the game
//call playRound to handle the specific round
//return the total aggregated game results

//TODOf complete comments
/**
* [getSnap]
* @return [return the value of snap]
*/

//TODO6 implement the getSnap method
int getSnap()
{
return this.snap;
}
//TODOg complete comments
/**
* [getCrackle]
* @return [return the value of crackle]
*/

//TODO7 implement the getCrackle method
int getCrackle()
{
return this.crackle;
}
//TODOh complete comments
/**
* [getPop]
* @return [returns the value of pop]
*/

//TODO8 implement the getPop method
int getPop()
{
return this.pop;
}
}
//end class

public class SnapCracklePopMain{

public static void main(String[] args){
  
// The scanner we will be using to accept user input
Scanner scan = new Scanner(System.in);
/* Initializing snap, crackle, pop, and round to invalid values to cause them
* to enter their respective User Input loops.
*/
int snap = -1;
int crackle = -1;
int pop = -1;
int rounds = -1;
  
// Our SnapCracklePop object
SnapCracklePop scp;
  
// Capture user input for snap, while also ensuring correctness
System.out.println("Enter an integer for your snap number.");
while(snap < 0){
System.out.println("Please enter a number greater than zero:");
try{
snap = Integer.parseInt(scan.nextLine());
} catch (Exception e) {
System.out.println("That is not a valid number. Please enter an integer greater than zero.");
}
}
  
// Capture user input for crackle, while also ensuring correctness
System.out.println("Enter an integer for your crackle number.");
while(crackle < 0){
System.out.println("Please enter a number greater than zero:");
try{
crackle = Integer.parseInt(scan.nextLine());
} catch(Exception e) {
System.out.println("That is not a valid number. Please enter an integer greater than zero.");
}
}
  
// Capture user input for pop, while also ensuring correctness
System.out.println("Enter an integer for your pop number.");
while(pop < 0){
System.out.println("Please enter a number greater than zero:");
try{
pop = Integer.parseInt(scan.nextLine());
} catch(Exception e) {
System.out.println("That is not a valid number. Please enter an integer greater than zero.");
}
}
  
// Initializing our SnapCracklePop object with the values we just obtained from the user
scp = new SnapCracklePop(snap, crackle, pop);
  
// Capture user input for rounds, while also ensuring correctness
System.out.println("How many rounds would you like to play?");
while(rounds < 0){
System.out.println("Please enter a number greater than zero:");
try{
rounds = Integer.parseInt(scan.nextLine());
} catch(Exception e) {
System.out.println("That is not a valid number. Please enter an integer greater than zero.");
}
}
  
// Printing results
System.out.println("Results:");
System.out.println(scp.playGame(rounds));

}

}

Sample Output:


Related Solutions

Monshimout is a game from the Cheyenne people and played by women. It could be played...
Monshimout is a game from the Cheyenne people and played by women. It could be played by two or more players, and if played by more than two, then the players divided into two equal teams. Game equipment consisted of five plum stones and a basket made of woven grass or willow twigs. The basket measured 3-4 inches deep, 8 inches across at the top, and almost 1/2 inch thick. The plum stones were left plain on one side, but...
In Japan, where consumers find it difficult to say “snap, crackle, and pop,” Kellogg changed its...
In Japan, where consumers find it difficult to say “snap, crackle, and pop,” Kellogg changed its slogan for Rice Crispies to “patchy, pitchy, putchy.” Kellogg also needed to change the name of “Bran Buds” cereal in Sweden, where the name roughly translates to “burned farmer.” In some countries, colors used on products and in ads have to be changed because white is a mourning color (Japan), purple equates to death (much of Latin America), and green equals jungle sickness or...
Develop a Java application to simulate a game played in an elementary classroom. In this game,...
Develop a Java application to simulate a game played in an elementary classroom. In this game, the teacher places herself in the center of a circle of students surrounding her. She then distributes an even number of pieces of candy to each student. Not all students will necessarily receive the same number of pieces; however, the number of pieces of candy for each student is even and positive. When the teacher blows a whistle, each student takes half of his...
Write a python program that simulates a simple dice gambling game. The game is played as...
Write a python program that simulates a simple dice gambling game. The game is played as follows: Roll a six sided die. If you roll a 1, 2 or a 3, the game is over. If you roll a 4, 5, or 6, you win that many dollars ($4, $5, or $6), and then roll again. With each additional roll, you have the chance to win more money, or you might roll a game-ending 1, 2, or 3, at which...
If you played this game 619 times how much would you expect to win or lose?
Suppose a basketball player has made 233 out of 303free throws. If the player makes the next 3 free throws, I will pay you $7. Otherwise you pay me $8Step 2 of 2 :  If you played this game 619 times how much would you expect to win or lose? Round your answer to two decimal places. Losses must be entered as negative.
What would be the equilibrium of the classic game “Chicken” if it was played as a...
What would be the equilibrium of the classic game “Chicken” if it was played as a Stackleberg game in which one player gets to decide first?
Many of you probably played the game “Rock, Paper, Scissors” as a child. Consider the following...
Many of you probably played the game “Rock, Paper, Scissors” as a child. Consider the following variation of that game. Instead of two players, suppose three players play this game, and let us call these players A, B, and C. Each player selects one of these three items—Rock, Paper, or Scissors—independent of each other. Player A will win the game if all three players select the same item, for example, rock. Player B will win the game if exactly two...
Nearly a decade-and-a-half ago The Economist magazine noted (“Pop, Crackle, Snap,” April 3, 2004), “Even desperate...
Nearly a decade-and-a-half ago The Economist magazine noted (“Pop, Crackle, Snap,” April 3, 2004), “Even desperate job-seekers think twice about accepting hazardous work such as coal-mining, cow slaughtering or cleaning up asbestos sites.” Oh, really?!? Suppose different types of people have different tastes for wages and safety. Specifically, Type 1 people are very safety-oriented while Type 2 will do “anything” for money. Suppose employers are able to provide different combinations of wages and safety. Specifically, for Type A employers safety...
Consider the Ultimatum Game, a two-player game often played in experimental economics labs. In the Ultimatum...
Consider the Ultimatum Game, a two-player game often played in experimental economics labs. In the Ultimatum Game, one player is given an amount of money and then instructed to give some arbitrary portion of it to an anonymous second player. The second player has the option of accepting the offer or rejecting it. If the second player rejects the offer, neither player gets anything. Now answer the following question if the First Player is given $100: (a) According to traditional...
Coin taking game This game is played between 2 players, player 1 and player 2. There...
Coin taking game This game is played between 2 players, player 1 and player 2. There are two piles of coins. The values of a coin can be any integer. Both players know the values of all coins in both piles. Player 1 makes the first move, and play alternates between the players. A move consists of taking a coin from the top of either of the piles (either player can take from either pile). The game ends when both...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT