Computer
Engineering Department
Bilkent University
Assignment No. 9
March 28, 2002
Notes: 1. Please READ the assignment. 2. Always bring your textbook to the lab for reference
purposes. 3. In this assignment
there is one page. 4. Study the
program before coming to the lab and try to solve it as much as possible. Keep it in your H drive so that it would be
easy to access it in the labs. You may
also keep it in diskette. 5.
Your assistants may slightly change the program as you work on it.
More practice in terms of top down design and modular programming using
methods.
At the beginning of each program you must indicate
your name, date, and the purpose of the program. Your programs must have proper indentation, and make sure that 1.
your variable names are meaningful, 2. your program has enough comments
and blank lines for readability. 3. Your programs must have an easy to
follow user interface, and for each printed number your program must provide
its explanation.
Game of craps: (Due to Serkan Bayraktar)
The following is the definition of a game known as
craps. A player rolls two dice (regular
6 face dice.) After each roll the sum
of the numbers on the upward face of the dice are calculated. If the sum is 7 or 11 on the first roll the
player wins. If the sum is 2, 3, or 12
on the first roll the player loses. If
the sum is 4, 5, 6, 8, 9, or 10, then the sum becomes the player’s point. To win, player must continue rolling dice
until he makes his point. The player
loses by rolling a 7 before making the point.
Here are some sample game outputs for a better understanding:
Game 1:
Player rolled 3 + 4 = 7 à
Player wins
Game 2:
Player rolled 6 + 6 = 12 à Player loses
Game 3:
Player rolled 4 + 6 = 10 à Player’s
point is 10
Player rolled 4 + 2 = 6 àGame goes
on
Player rolled 1 + 4 = 5 àGame goes
on
Player rolled 5 + 5 = 10 àPlayer
makes his point and wins
Game 4:
Player rolled 4 + 2 = 6 à Player’s
point is 6
Player rolled 1 + 2 = 3 àGame goes
on
Player rolled 1 + 3 = 4 àGame goes
on
Player rolled 5 + 2 = 7 àPlayer
loses
The game of
craps can be modified to allow wagering (bahis.) Assume that the player begins the game with a certain amount of
money (his account.) Then he is
prompted to enter a wager. You must
only check if the amount of wager is smaller than the total amount he has in
his account. Only after he enters a
valid amount of wager, game starts. If
the player wins the game, the amount of wager is added to his account, other
wise it is decremented. Game end if the
player busts (iflas) or he enters 0 (zero) as wager.
Implement the game of craps with wagering. You must have a method to roll dice, a
method for each run of the game, a method to control user input, user account,
and if the game continues, and a main method for test. The dice roller method should return result
of a roll of a dice (so you roll each dice one by one), the game method should
return if player wins or loses (boolean ??.)
Hint: Rolling a dice (i.e., obtaining
a random face value) can be implemented with the following statement (see p.
180 of the textbook for a similar problem): faceValue= (int) (Math.random( ) *
6) + 1;
Make sure that your program is seen and approved
by your assistants. If they have
different instructions regarding grading please follow their instructions.