• The method will output the die roll value each time the die is rolled. • Rolling will stop when the sum of all rolls is equal to or greater than the specified sum (the integer parameter). You may assume the integer value passed to your method is greater than or equal to 0. • You are to exactly reproduce the format shown below. Example #1 For example, given the following code: Random r = new Random(); rollSum(r, 10); May have an output of: Roll: 6 Roll: 2 Roll: 5 Target of 10 reached with 13. In this example, 10 was the target sum. 6 is less than 10, so the die was rolled again. 6 + 2 = 8 is less than 10, so another roll. 6 + 2 + 5 = 13, so the rolling stopped. This example would return 3 because the die was rolled three times (6, 2, and 5).

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Write a static method called rollSum that takes a Random object and an integer
as parameters and returns the number of dice rolls it takes to roll the sum
specified.
• The method should use the Random object to select numbers in the range of
1 to 6 inclusive (simulating a six-sided die roll) where each number is equally
likely to be chosen.
• The method will output the die roll value each time the die is rolled.
• Rolling will stop when the sum of all rolls is equal to or greater than the
specified sum (the integer parameter). You may assume the integer value
passed to your method is greater than or equal to 0.
• You are to exactly reproduce the format shown below.
Example #1
For example, given the following code:
Random r = new Random();
rollSum(r, 10);
May have an output of:
Roll: 6
Roll: 2
Roll: 5
Target of 10 reached with 13.
In this example, 10 was the target sum. 6 is less than 10, so the die was rolled
again. 6 + 2 = 8 is less than 10, so another roll. 6 + 2 + 5 = 13, so the rolling
stopped.
This example would return 3 because the die was rolled three times (6, 2, and 5).
Transcribed Image Text:Write a static method called rollSum that takes a Random object and an integer as parameters and returns the number of dice rolls it takes to roll the sum specified. • The method should use the Random object to select numbers in the range of 1 to 6 inclusive (simulating a six-sided die roll) where each number is equally likely to be chosen. • The method will output the die roll value each time the die is rolled. • Rolling will stop when the sum of all rolls is equal to or greater than the specified sum (the integer parameter). You may assume the integer value passed to your method is greater than or equal to 0. • You are to exactly reproduce the format shown below. Example #1 For example, given the following code: Random r = new Random(); rollSum(r, 10); May have an output of: Roll: 6 Roll: 2 Roll: 5 Target of 10 reached with 13. In this example, 10 was the target sum. 6 is less than 10, so the die was rolled again. 6 + 2 = 8 is less than 10, so another roll. 6 + 2 + 5 = 13, so the rolling stopped. This example would return 3 because the die was rolled three times (6, 2, and 5).
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY