Question

In: Computer Science

Your Tasks Step 1 Write the comments in the SnapCracklePop.java using the java doc style in...

Your Tasks

Step 1 Write the comments in the SnapCracklePop.java using the java doc style in zyBooks 3.8. See TODOa to TODOh.  

Step 2 Complete the class definition, variable declarations, constructor, and all the methods by reading the instructions in SnapCracklePop.java. See TODO1 to TODO7. (DONE I NEED HELP WITH STEP 1)

1 //TODOa complete this javadoc comment
2 /**
3 * [The class description]
4 * @author [Your Name]
5 * @version 1.0
6 */
7
8 //TODO1: declare the SnapCracklePop class
9 class SnapCracklePop{
10 //TODOb Complete Comments
11 /**
12 * [Instance Variable Descriptions]
13 */
14
15 //TODO2 Declare private instance variables
16 //to store Snap, Crackle, and Pop values
17 private int snap;
18 private int crackle;
19 private int pop;
20
21 //TODOc complete comments
22 /**
23 * [Constructor Description]
24 * @param [param name] [what the param represents]
25 * @param [param name] [what the param represents]
26 * @param [param name] [what the param represents]
27 */
28
29 /* The constructor takes in three ints,
30 * which must be assigned to their instance variables and initialized.
31 */
32
33 //TODO3 Write the constructor
34
35
36 //TODOe complete comments
37 /**
38 * [Method Description]
39 * @param [param name] [What the parameter represents]
40 * @return [What the method returns]
41 */
42 public SnapCracklePop(int snap, int crackle, int pop){
43 this.snap = snap;
44 this.crackle = crackle;
45 this.pop = pop;
46 }
47
48 /* playRound() is a helper method for playGame().
49 * It takes an int parameter representing the
50 * current round of play, and returns the
51 * String result for that specific round only.
52 */
53
54 //TODO4 implement the playRound method
55 String playRound(int round){
56 //set the string to empty
57 String output = "";
58 //if the current round number is multiple of snap
59 if(round % this.snap == 0){
60 output += "snap";
61 }
62 //if the current round number is multiple of crackle
63 if(round % this.crackle == 0){
64 output += "crackle";
65 }
66 //if the current round number is multiple of pop
67 if(round % this.pop == 0){
68 output += "pop";
69 }
70 //if the output is empty
71 if(output == ""){
72 output += round;
73 }
74
75 return output;
76 }
77 //TODOd complete comments
78 /**
79 * [Method Description]
80 * @param [param name] [What the parameter represents]
81 * @return [What the method returns]
82 */
83
84 /* playGame() takes a single parameter representing the rounds and returns
85 * a String representing the result of the entire game. The helper method
86 * playRound() may be useful here, so you may want to complete it first.
87 */
88
89 //TODO5 implement the playGame method
90 String playGame(int rounds){
91 String result = "";
92 //set the number of snaps,crackles,pops to 0
93 int snaps = 0;
94 int crackles = 0;
95 int pops = 0;
96 for(int i = 1;i <= rounds;i++) {
97 //call the play round function
98 String current_result = playRound(i);
99 //if the current result string has snap in it
100 if(current_result.indexOf("snap") != -1){
101 // to get total number of snaps at last-increment it
102 snaps++;
103 }
104 //if the current result string has crackle in it
105 if(current_result.indexOf("crackle") != -1){
106 //to get total number of crackles at last-increment crackles
107 crackles++;
108 }
109 //if the current result string has pop in it
110 if(current_result.indexOf("pop") != -1){
111 //to get total number of pops at last-increment pops
112 pops++;
113 }
114 result += current_result + "\n";
115 }
116 //add the values to the result with description
117 result += "Number of Snaps: " + snaps + "\n";
118 result += "Number of Crackles: " + crackles + "\n";
119 result += "Number of Pops: " + pops + "\n";
120 return result;
121 }
122
123 //Loop through the rounds of the game
124 //call playRound to handle the specific round
125 //return the total aggregated game results
126
127 //TODOf complete comments
128 /**
129 * [Method Description]
130 * @return [What this method returns]
131 */
132
133 //TODO6 implement the getSnap method
134 int getSnap(){
135 return this.snap;
136 }
137
138 //TODOg complete comments
139 /**
140 * [Method Description]
141 * @return [What this method returns]
142 */
143
144 //TODO7 implement the getCrackle method
145 int getCrackle(){
146 return this.crackle;
147 }
148 //TODOh complete comments
149 /**
150 * [Method Description]
151 * @return [What this method returns]
152 */
153
154 //TODO8 implement the getPop method
155 int getPop(){
156 return this.pop;
157 }
158 }
159
160
161
162 //end class

I finished to do 1-7 but i need help with to do a-h with the comments. please help! thanks!

Solutions

Expert Solution

I've completed all the comments from a-h. I would make my changes bold and italic for better understanding. Please leave an upvote if you like this answer. Thank you.

Code :

Important - Please delete the name the name alex and write your name.

//TODOa complete this javadoc comment
/**
* The class SnapCracklePop is a class which plays game with the help with the help of snap, crackle and pop
* @author Alex(Suppose if your name is Alex, you have to write your name here.)
* @version 1.0
*/

//TODO1: declare the SnapCracklePop class
class SnapCracklePop{
//TODOb Complete Comments
/**
* snap - private int used to store the value of snap.
* crackle - private int used to store the value of crackle.
* pop - private int used to store the value of 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
/**
* The constructor of this class takes three arguments and assigns them to the fields snap, crackle and pop
* @param snap value of snap
* @param crackle value of crackle
* @param pop 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 is a helper method for playGame().
* It takes an int parameter representing the curround round of play
* and retruns the result for that round
* @param round the current round of the play
* @return output the string result for that specefic 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() takes a single parameter representing the rounds and returns
* a String representing the result of the entire game.
* @param rounds number of rounds in the game.
* @return result the complete result of the entire 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){
String result = "";
//set the number of snaps,crackles,pops to 0
int snaps = 0;
int crackles = 0;
int pops = 0;
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){
// to get total number of snaps at last-increment it
snaps++;
}
//if the current result string has crackle in it
if(current_result.indexOf("crackle") != -1){
//to get total number of crackles at last-increment crackles
crackles++;
}
//if the current result string has pop in it
if(current_result.indexOf("pop") != -1){
//to get total number of pops at last-increment pops
pops++;
}
result += 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
/**
* This method returns the value of the variable snap.
* @return snap
*/

//TODO6 implement the getSnap method
int getSnap(){
return this.snap;
}

//TODOg complete comments
/**
* This method returns the value of the variable crackle.
* @return crackle
*/

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

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

Solution ends.

Please comment and let me know if you have any further doubts. Please upvote this answer if you like it.

Thank you.

Have a good day.


Related Solutions

Please show solution and comments for this data structure using java.​ Implement a program in Java...
Please show solution and comments for this data structure using java.​ Implement a program in Java to convert an infix expression that includes (, ), +, -, *,     and / to postfix expression. For simplicity, your program will read from standard input (until the user enters the symbol “=”) an infix expression of single lower case and the operators +, -, /, *, and ( ), and output a postfix expression.
Write a Java program that will use a two-dimensional array to solve the following tasks: 1....
Write a Java program that will use a two-dimensional array to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5. Create a...
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name, that does the following: Create two arrays that will hold related information. You can choose any information to store, but here are some examples: an array that holds a person's name and an array that hold's their phone number an array that holds a pet's name and an array that holds what type of animal that pet is an array that holds a student's...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name, that does the following: Declare an array reference variable called myFavoriteSnacks for an array of String type. Create the array so that it is able to hold 10 elements - no more, no less. Fill the array by having each array element contain a string stating one of your favorite foods/snacks. Note: Only write the name of the snack, NO numbers (i.e. Do not...
write code with proper comments for ever step the code should be in form of pseudocode                            &
write code with proper comments for ever step the code should be in form of pseudocode                                    To Print Triangle of any size, by taking size as input. To Print Triangle of any size, by taking size as input. If size is 4 then triangle is: To calculate Factorial of any number. To calculate the power of any given number. To Print Table of Any Number up till 10: as shown in this figure. for a program which reads 10 integers...
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three integer values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
Hello, Please write this program in java and include a lot of comments and please try...
Hello, Please write this program in java and include a lot of comments and please try to make it as simple/descriptive as possible since I am also learning how to code. The instructions the professor gave was: Create your own class Your own class can be anything you want Must have 3 instance variables 1 constructor variable → set the instance variables 1 method that does something useful in relation to the class Create a driver class that creates an...
Lab 02 Final Grade Calculator **** I need it in JAVA **** **** write comments with...
Lab 02 Final Grade Calculator **** I need it in JAVA **** **** write comments with the code **** Objective: Write a program that calculates a final grade! The program should read in a file and then calculates the final grade based on those scores. Files read into this system are expected to follow this format: <Section0>\n <Grade0 for Section0>\n <Grade1 for Section0>\n … <GradeX for Section0>\n <Section1>\n <Grade0 for Section1>\n … <GradeY for Section1> <Section2> … <SectionZ> Sections denote...
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three int||eger values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
write this program in java... don't forget to put comments. You are writing code for a...
write this program in java... don't forget to put comments. You are writing code for a calendar app, and need to determine the end time of a meeting. Write a method that takes a String for a time in H:MM or HH:MM format (the program must accept times that look like 9:21, 10:52, and 09:35) and prints the time 25 minutes later. For example, if the user enters 9:21 the method should output 9:46 and if the user enters 10:52...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT