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

Instructions for a java coding exercise where students are required to write a code segment to roll two dice 1000 times and keep track of the number of times the first die rolls larger, the second die rolls larger, and when both dice roll the same number. The document also suggests modifications to roll the dice until one or both dice have rolled larger a specific number of times.

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-v9c-1
koofers-user-v9c-1 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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