Docsity

Java Code Exercise: Rolling Dice and Tracking Statistics - Prof. Ronnie W. Smith, Assignments of Computer Science

Toggle sidebar
bg1
CSCI 2310
Class Exercise
March 17, 2009
Write a segment of Java code that repeatedly rolls two dice, keeping the following statistics:
• Number of times the roll of the first die is larger
• Number of times the roll of the second die is larger
• Number of times the roll of the two dice is the same
Your code segment should roll the pair of dice 1000 times, and produce the following output.
Die 1 had larger roll ??? times
Die 2 had larger roll ??? times
Two dice had same roll ??? times
You may assume that you have available the Dice class that we have defined previously (which
of course has the roll() method).
How would you change your code to repeatedly roll the dice until one of the two dice has had the
larger roll 500 times? What about until both dice have had the larger roll 500 times?
Protocol
1. Work independently for 15 minutes
2. Find a partner and discuss for 15 minutes, decide upon your best solution (which may
mix features of both your solutions)
3. Find another team and discuss with them for 15 minutes, deciding upon your best
solution overall

Partial preview of the text

Download Java Code Exercise: Rolling Dice and Tracking Statistics - Prof. Ronnie W. Smith and more Assignments Computer Science in PDF only on Docsity!

CSCI 2310

Class Exercise

March 17, 2009

Write a segment of Java code that repeatedly rolls two dice, keeping the following statistics:

  • Number of times the roll of the first die is larger
  • Number of times the roll of the second die is larger
  • Number of times the roll of the two dice is the same

Your code segment should roll the pair of dice 1000 times, and produce the following output.

Die 1 had larger roll ??? times Die 2 had larger roll ??? times Two dice had same roll ??? times

You may assume that you have available the Dice class that we have defined previously (which of course has the roll() method).

How would you change your code to repeatedly roll the dice until one of the two dice has had the larger roll 500 times? What about until both dice have had the larger roll 500 times?

Protocol

  1. Work independently for 15 minutes
  2. Find a partner and discuss for 15 minutes, decide upon your best solution (which may mix features of both your solutions)
  3. Find another team and discuss with them for 15 minutes, deciding upon your best solution overall