SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. • Assume that the classes listed in the Java Quick Reference have been imported where appropriate. • Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. • In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit. This question involves the creation and use of a spinner to generate random numbers in a game. A GameSpinner object represents a spinner with a given number of sectors, all equal in size. The GameSpinner class supports the following behaviors. . Creating a new spinner with a specified number of sectors • Spinning a spinner and reporting the result • Reporting the length of the current run, the number of consecutive spins that are the same as the most recent spin The following table contains a sample code execution sequence and the corresponding results.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

See the attached below.

SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA.
• Assume that the classes listed in the Java Quick Reference have been imported where appropriate.
• Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied.
• In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit.
This question involves the creation and use of a spinner to generate random numbers in a game. A GameSpinner object represents a spinner with a given number of sectors, all equal in size. The GameSpinner class supports the following behaviors.
• Creating a new spinner with a specified number of sectors
• Spinning a spinner and reporting the result
• Reporting the length of the current run, the number of consecutive spins that are the same as the most recent spin
The following table contains a sample code execution sequence and the corresponding results.
Statements
GameSpinner g = new
GameSpinner (4);
g.currentRun();
g.spin();
g.currentRun();
g.spin();
g.currentRun();
g.spin();
g.currentRun();
g.spin();
g.currentRun();
g.spin();
g.spin();
g.spin();
g.currentRun();
Value Returned
(blank if no value
returned)
0
3
1
3
2
4
1
3
1
1
1
1
3
Comment
Creates a new spinner with four sectors
Returns the length of the current run. The length of the current run is initially because no spins have occurred.
Returns a random integer between 1 and 4, inclusive. In this case, 3 is returned.
The length of the current run is 1 because there has been one spin of 3 so far.
Returns a random integer between 1 and 4, inclusive. In this case, 3 is returned.
The length of the current runis 2 because there have been two 3s in a row.
Returns a random integer between 1 and 4, inclusive. In this case, 4 is returned.
The length of the current run is 1 because the spin of 4 is different from the value of the spin in the previous run of two 3s.
Returns a random integer between 1 and 4, inclusive. In this case, 3 is returned.
The length of the current run is 1 because the spin of 3 is different from the value of the spin in the previous run of one 4.
Returns a random integer between 1 and 4, inclusive. In this case, 1 is returned.
Returns a random integer between 1 and 4, inclusive. In this case, 1 is returned.
Returns a random integer between 1 and 4, inclusive. In this case, 1 is returned.
The length of the current run is 3 because there have been three consecutive 1s since the previous run of one 3.
Write the complete GameSpinner class. Your implementation must meet all specifications and conform to the example.
Transcribed Image Text:SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. • Assume that the classes listed in the Java Quick Reference have been imported where appropriate. • Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. • In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit. This question involves the creation and use of a spinner to generate random numbers in a game. A GameSpinner object represents a spinner with a given number of sectors, all equal in size. The GameSpinner class supports the following behaviors. • Creating a new spinner with a specified number of sectors • Spinning a spinner and reporting the result • Reporting the length of the current run, the number of consecutive spins that are the same as the most recent spin The following table contains a sample code execution sequence and the corresponding results. Statements GameSpinner g = new GameSpinner (4); g.currentRun(); g.spin(); g.currentRun(); g.spin(); g.currentRun(); g.spin(); g.currentRun(); g.spin(); g.currentRun(); g.spin(); g.spin(); g.spin(); g.currentRun(); Value Returned (blank if no value returned) 0 3 1 3 2 4 1 3 1 1 1 1 3 Comment Creates a new spinner with four sectors Returns the length of the current run. The length of the current run is initially because no spins have occurred. Returns a random integer between 1 and 4, inclusive. In this case, 3 is returned. The length of the current run is 1 because there has been one spin of 3 so far. Returns a random integer between 1 and 4, inclusive. In this case, 3 is returned. The length of the current runis 2 because there have been two 3s in a row. Returns a random integer between 1 and 4, inclusive. In this case, 4 is returned. The length of the current run is 1 because the spin of 4 is different from the value of the spin in the previous run of two 3s. Returns a random integer between 1 and 4, inclusive. In this case, 3 is returned. The length of the current run is 1 because the spin of 3 is different from the value of the spin in the previous run of one 4. Returns a random integer between 1 and 4, inclusive. In this case, 1 is returned. Returns a random integer between 1 and 4, inclusive. In this case, 1 is returned. Returns a random integer between 1 and 4, inclusive. In this case, 1 is returned. The length of the current run is 3 because there have been three consecutive 1s since the previous run of one 3. Write the complete GameSpinner class. Your implementation must meet all specifications and conform to the example.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education