[ next ] [ prev ] [ contents ] [ up to Appendix A -- What is Object Oriented? ] Invitation To Ruby

Dice in Ruby (cont)

  1: def histograms
  2:   user = DiceUser.new
  3:   user.examine(StandardDice.new)
  4:   puts "Six Sided Dice"
  5:   user.histogram
  6:   puts ""
  7:   puts "Coin Operated Dice"
  8:   user.examine(CoinOperatedDice.new)
  9:   user.histogram
 10: end

Here we use DiceUser.

  • [2-5] Introduce some constants
  • [7-13] Throw a dice 10000 times and record the number of times each number turns up.
  • [15-19] Display a histogram of the number of times.


[ next ] [ prev ] [ contents ] [ up to Appendix A -- What is Object Oriented? ] Copyright 2002 by Jim Weirich.
All rights reserved.