![]() |
CS 111 - Introduction to Computer Science
Homework #10 |
1. Dice Histogram: Call your class DiceHistogram.java. In this exercise, you will simulate the throwing of 2 standard six-sided dice a given number of times and display the resulting distribution as a text-based histogram. First, ask the user how many time to roll the dice. Then simulate the dice rolling and print the maximum number of times a sum was rolled. Next print lines for each possible dice roll showing a number of asterisks proportional to the number of times the sum was rolled. Scale the number of asterisks such that the sum rolled the most will have 60 asterisks. Example transcript (user input bold underlined):
How many rolls? 1000000 Max count: 166039 2 ********** 3 ******************** 4 ****************************** 5 **************************************** 6 ************************************************** 7 ************************************************************ 8 ************************************************** 9 **************************************** 10 ****************************** 11 ******************** 12 *********
Possible "stepping stones" towards the goal: (1) Print the given number of roll sums. Remember: The sum of two 6-sided dice is different than a single roll of an 11-sided die numbered 2 through 12. (Why?) (2) Use an array to count the number of rolls for each sum and print a table (i.e. numbers instead of histogram asterisks above). (3) Compute and print the maximum count. (4) Round (60.0 * count / maximum) for each count to compute the number of asterisks, and print the histogram as shown.
2. Chomp: Chomp is a Nim-type game in which two players take bites of a gridded cookie in turn. Each bite at a given row and column consumes the cookie at, below, and to the right of that position. The player taking the last bite loses.
For this assignment, design and implement Chomp.java such that two players can play a text-based version of chomp for a given board size up to at least size 10-by-10. Initially print game instructions. Before each turn, provide a text representation of the board, indicate the current player, and request the player's bite position. Entry of an illegal bite position should yield an error message and another bite position request for the player. When the game is over, indicate the winner. An example transcript is available, although your implementation need not have the same look.
Chomp Resources: