Question

III. Overview & Requirements:

The following description has been adopted from Deitel & Deitel. One of the most popular games of chance is a dice game called "craps," which is played in casinos and back alleys throughout the world. The rules of the game are straightforward:

A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5, and 6 spots. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on the first throw, the player wins. If the sum is 2, 3, or 12 on the first throw (called "craps"), the player loses (i.e. the "house" wins). If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then the sum becomes the player's "point." To win, you must continue rolling the dice until you "make your point." The player loses by rolling a 7 before making the point.

Write a program that implements a craps game according to the above rules. The game should allow for wagering. This means that you need to prompt that user for an initial bank balance from which wagers will be added or subtracted. Before each roll prompt the user for a wager. Once a game is lost or won, the bank balance should be adjusted. As the game progresses, print various messages to create some "chatter" such as, "Sorry, you busted!", or "Oh, you're going for broke, huh?", or "Aw cmon, take a chance!", or "You're up big, now's the time to cash in your chips!"

Use the below functions to help you get started! You may define more than the ones suggested if you wish!

*(5 pts) void print_game_rules (void) — Prints out the rules of the game of "craps".

*(5 pts) double get_bank_balance (void) - Prompts the player for an initial bank balance from which wagering will be added or subtracted. The player entered bank balance (in dollars, i.e. $100.00) is returned.

*(5 pts) double get_wager_amount (void) - Prompts the player for a wager on a particular roll. The wager is returned.

*(5 pts) int check_wager_amount (double wager, double balance) - Checks to see if the wager is within the limits of the player's available balance. If the wager exceeds the player's allowable balance, then 0 is returned; otherwise 1 is returned.

*(5 pts) int roll_die (void) - Rolls one die. This function should randomly generate a value between 1 and 6, inclusively. Returns the value of the die.

*(5 pts) int calculate_sum_dice (int die1_value, int die2_value) - Sums together the values of the two dice and returns the result. Note: this result may become the player's point in future rolls.

*(10 pts) int is_win_loss_or_point (int sum_dice) - Determines the result of the first dice roll. If the sum is 7 or 11 on the roll, the player wins and 1 is returned. If the sum is 2, 3, or 12 on the first throw (called "craps"), the player loses (i.e. the "house" wins) and 0 is returned. If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then the sum becomes the player's "point" and -1 is returned.

*(10 pts) int is_point_loss_or_neither (int sum_dice, int point_value) - Determines the result of any successive roll after the first roll. If the sum of the roll is the point_value, then 1 is returned. If the sum of the roll is a 7, then 0 is returned. Otherwise, -1 is returned.

*(5 pts) double adjust_bank_balance (double bank_balance, double wager_amount, int add_or_subtract) - If add_or_subtract is 1, then the wager amount is added to the bank_balance. If add_or_subtract is 0, then the wager amount is subtracted from the bank_balance. Otherwise, the bank_balance remains the same. The bank_balance result is returned.

*(5 pts) void chatter_messages (int number_rolls, int win_loss_neither, double initial_bank_balance, double current_bank_balance) - Prints an appropriate message dependent on the number of rolls taken so far by the player, the current balance, and whether or not the player just won his roll. The parameter win_loss_neither indicates the result of the previous roll.

*(10 pts) Others?

*(20 pts) A main ( ) function that makes use of the above functions in order to play the game of craps as explained above. Note that you will most likely have a loop in your main ( ) function (or you could have another function that loops through the game play).

Have a great time with this assignment! There is plenty of room for creativity! Note: I have not stated how you must display the game play! You may do as you wish!

USING VISUAL STUDIO WITH A MAIN.C, EQUATIONS.C AND EQUATIONS.H FILES

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

import java.util.Scanner;

public class craps {
   public double balance;
   Scanner in=new Scanner(System.in);
  
   void print_game_rules()
   {
   System.out.println("************Instructions ********************");
   System.out.println("1.A player rolls two dice\n2.If the sum is 7 or 11 on the first throw ,the player wins.\n3.If the sum is 2, 3, or 12 on the first throw (called craps), the player loses (i.e. the house wins).\n4. If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then the sum becomes the player's \"point.\" \n5.To win, you must continue rolling the dice until you \"make your point\".\n5. The player loses by rolling a 7 before making the point.\n---------------------------------------------\n");
   }
  
   double get_bank_balance ()
   {
   System.out.println("Please enter your bank balance");
   balance=in.nextDouble();
   return balance;
   }
  
   double get_wager_amount ()
   {
   double wager;
   System.out.println("enter the wager amount for the round");
   wager=in.nextDouble();
   return wager;
   }
  
   int check_wager_amount (double wager, double balance)
   {
   if(wager>balance)
   return 0;
   else return 1;
   }
   int roll_die ()
   {
   int ran = (int )(Math.random() * 6 + 1);
   return ran;
   }
  
   int calculate_sum_dice (int die1_value, int die2_value)
   {
   int sum=die1_value+die2_value;
   System.out.println("your round sum is:"+sum);
   return sum;
   }
  
   int is_win_loss_or_point (int sum_dice)
   {
   if(sum_dice==7 || sum_dice==11 )
   return 1;
   else if(sum_dice==2 ||sum_dice==3||sum_dice==12)
   return 0;
   else
   return -1;
   }
  

int is_point_loss_or_neither (int sum_dice, int point_value)
{
if(sum_dice==7)
return 0;
else if(sum_dice==point_value)
return 1;
else return -1;
}

double adjust_bank_balance (double bank_balance, double wager_amount, int add_or_subtract)
{
if(add_or_subtract==1)
bank_balance+=wager_amount;
else if (add_or_subtract==0)
bank_balance-=wager_amount;
return bank_balance;
}

void chatter_messages (int number_rolls, int win_loss_neither, double initial_bank_balance, double current_bank_balance)
{
if(initial_bank_balance<current_bank_balance)
System.out.println("You're up big, now's the time to cash in your chips!");
if(win_loss_neither==-1)
System.out.println("Oh !common Take a chance");

}

public static void main(String args[]){
   Scanner on=new Scanner(System.in);
   craps c= new craps();
   c.print_game_rules ();
   int point=0;
   double initial_balance=c.get_bank_balance();
   double balance=initial_balance;
   int i=1;
   int x=0;
   int val=0;
   while(true)
   {
       double wager=c.get_wager_amount();
      
       x=c.check_wager_amount(wager,balance);
       if(x==0)
       {System.out.println("wager is greater than the current balance in your account\n do you want to choose anothe wagon amount:If yes press 1 else press any key to exit");
       int ch=on.nextInt();
       if(ch==1)
           continue;
       else
           break;
       }
       int r1=c.roll_die();
       int r2=c.roll_die();
       int sum=c.calculate_sum_dice(r1,r2);
       if(i==1)
       {
              val=c.is_win_loss_or_point(sum);
           if (val==1)
           {
               System.out.println("Hey!!! you won the game");
               balance=c.adjust_bank_balance (balance, wager, 1);
                break;
           }
           else if( val==0)
           {
               System.out.println("oops!!! you loss the the game");
               balance= c.adjust_bank_balance (balance, wager, 0);
               break;
           }
           else
           {
           point=sum;
          
               System.out.println("you neither win nor loss.got your point continue with next round");
           }
       }
           else
           {
           val=c.is_point_loss_or_neither (sum,point);
               if(val==1)
               {
                   System.out.println("Hey!!! you won the game");
                   balance=c.adjust_bank_balance (balance, wager, 1);
                    break;
                }
               else if( val==0)
               {
                   System.out.println("oops!!! you loss the the game");
                   balance= c.adjust_bank_balance (balance, wager, 0);
                   break;
               }
               else if (val==-1)
                   System.out.println("continue wiyh next throw");
           }
       c.chatter_messages (i,1, initial_balance,balance);
       i++;
   }
      
              
              
       }
      
      
      
      
      
      
  
  
  
}

Sample output:

************Instructions ********************
1.A player rolls two dice
2.If the sum is 7 or 11 on the first throw ,the player wins.
3.If the sum is 2, 3, or 12 on the first throw (called craps), the player loses (i.e. the house wins).
4. If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then the sum becomes the player's "point."
5.To win, you must continue rolling the dice until you "make your point".
5. The player loses by rolling a 7 before making the point.
---------------------------------------------

Please enter your bank balance
10000
enter the wager amount for the round
3000
your round sum is:9
you neither win nor loss.got your point continue with next round
enter the wager amount for the round
4000
your round sum is:5
continue wiyh next throw
enter the wager amount for the round
3000
your round sum is:7
oops!!! you loss the the game

Add a comment
Know the answer?
Add Answer to:
III. Overview & Requirements: The following description has been adopted from Deitel & Deitel. One of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • C# Code: Write the code that simulates the gambling game of craps. To play the game,...

    C# Code: Write the code that simulates the gambling game of craps. To play the game, a player rolls a pair of dice (2 die). After the dice come to rest, the sum of the faces of the 2 die is calculated. If the sum is 7 or 11 on the first throw, the player wins and the game is over. If the sum is 2, 3, or 12 on the first throw, the player loses and the game is...

  • 2. "Craps" is a game played by rolling two fair dice. To play one round of...

    2. "Craps" is a game played by rolling two fair dice. To play one round of this game, the player rolls the dice and the outcome is determined by the following rules: If the total number of dots is 7 or 11 (a "natural"), then the player wins. If the total number of dots is 2, 3, or 12 C'craps"), then the player loses. If the total number of dots is 4, 5, 6,8,9, or 10, then this number is...

  • in c programming and c++filed Exercise 1: A Game of guessing number Set the default upper...

    in c programming and c++filed Exercise 1: A Game of guessing number Set the default upper and lower limits to be 1-100, and ask you to guess a number. If you do not guess the correct number, the program will nicely" automatically adjust the upper or the lower limits to save your day until you guess it. 2 0 12. 51 - 100 3 2 51 74 22 65 74 85 2 71 74 3 . 2 73 74 75...

  • Write a c++ program that simulates a million of games in craps. I am having a...

    Write a c++ program that simulates a million of games in craps. I am having a trouble getting to loop a million of times. I am trying to use a const for a million. This is the code so far. #include <iostream> #include <cstdlib>// contains prototypes for functions srand and rand #include <ctime>// contains prototype for function time #include <iomanip> using namespace std; int rollDice(); // rolls dice, calculates and displays sum void printstats(); int totroll = 0, games, point,...

  • Craps

    Write a C++ game that plays Craps. Craps is a game played with a pair of dice. The shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the ‘come out roll’) is a 7 or 11, the shooter wins the game. If the opening roll results in a 2 (snake eyes), 3 or 12 (box cars), the shooter loses,...

  • This is for C++ #include <random> #include <iostream> #include <ctime> using namespace std; /* In the...

    This is for C++ #include <random> #include <iostream> #include <ctime> using namespace std; /* In the game of craps, a shooter rolls 2 dice and adds the dots on the upper most faces of the dice. 7 or 11 on the first roll wins, 2, 3, or 12 on the first roll loses, andthing else is call the point and the player rolls again The following program fragment uses 1-way if statements simulate the 1st roll of the dice. Replace...

  • Hello, Could you please help me code this program in Java? It is important that all...

    Hello, Could you please help me code this program in Java? It is important that all rules are carefully followed. Using the PairOfDice class from PP 4.9, design and implement a class to play a game called Pig. In this game, the user competes against the computer. On each turn, the current player rolls a pair of dice and accumulates points. The goal is to reach 100 points before your opponent does. If, on any turn, the player rolls a...

  • (Java Coding) Game1: You win if one get one six in four rolls of one dice. (To be Simulated 1,000,000 times) Game2: You win if one get double sixes in twenty four rolls of two dice. (To be simulated 1...

    (Java Coding) Game1: You win if one get one six in four rolls of one dice. (To be Simulated 1,000,000 times) Game2: You win if one get double sixes in twenty four rolls of two dice. (To be simulated 1,000,000 times) Given below that the class die, oddstester, and gameSimulator(partially complete and the bold missing parts need to be done), need to find the probability of winning game 1 and 2 (after the 1 million plays) hence the getWins and...

  • Example Consider the following dice game. A pair of standard ( fair ) dice are repeatedly...

    Example Consider the following dice game. A pair of standard ( fair ) dice are repeatedly rolled. If a ’ 7 ’ comes up before an ’ 11 ’ , then the player wins, otherwise the player loses. Let W be the event that the player wins. Find P(W). To say the dice are fair is equivalent to assuming that Laplace’s rule holds and the 36 possible outcomes for a throw of the dice are equally likely. For convenience, an...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT