Comp
110
Homework
Assignment #2
Due:
9/30/2009
Design
algorithms for the following two problems.
Your main algorithm should contain just the main steps, and for each
step that is non trivial, develop a separate algorithm for it. These will become methods in your program. You may want to develop a top-down design
diagram for your algorithm like the one below for the printCalendar
problem.
2 3
5 7 11 101
131 151 181
191
313 353 373
383 727 757
787 797 919
929
(Compare with problem 3.27 on page 176 of the
textbook.)
Roll two dice. Each die has six faces representing values 1,
2, . . ., and 6, respectively. Check the sum of the two dice. If the sum is 2, 3, or 12 (called craps) you lose; if the sum is 7 or 11
(called natural), you win; if the sum is
another value (i.e., 4, 5, 6, 8, 9, or 10), a point is established.
Continue to roll the dice until either a 7 or the same point value is
rolled. If 7 is
rolled, you lose. Otherwise, you win.
Your algorithm should be for a
single player. Here are some sample
runs:
You rolled 5 + 6 = 11
You win
You rolled 1 + 2 = 3
You lose
You rolled 4 + 4 = 8
Point is 8
You rolled 6 + 2 = 8
You win
You rolled 3 + 2 = 5
Point is 5
You rolled 2 + 5 = 7
You lose
(Compare with problem 5.29 on pages 176 &
177 of the textbook.)