Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Code a craps game in java using THESE INSTRUCTIONS. YOU MUST FOLLOW THESE GUIDLE

ID: 3705958 • Letter: C

Question

Code a craps game in java using THESE INSTRUCTIONS. YOU MUST FOLLOW THESE GUIDLELINES. USE CODE BELOW FOR THE ROLL AND DISPLAT ROLL PORTION:

  

/*

* Craps.java

*

* Uses the Math.random and a switch statement to display a roll of two dice

*

* Requirements:

*

* Complete the game of craps as specified in the to do document

*

*

*

* Analysis

* main:

*        Input: choice

*        process: results

*        output win or lose statement

*

* play:

*        Input: none

*        process: none

*        output win or lose statement

*

*

* point(p)

*            parameter p

*            input dummy

*            process results, done

*            output results

*   

* roll:

*        parameters none

*        input: none

*        process d1,d2

*        output none

*        return total

*

* displayRoll

*        parameters roll

*        input none

*        process none

*        output dots

*        return none

*

*

*

*

*

* design

*

* main

*        repeat

*            results = call play()

*            output results

*            if results is 1 then

*                display win statement

*            else results is 0 then

*                display lose statement

*            endif

*           

*            prompt to play again?

*            input choice

*        while user inputs y

*

* play()

*        total = call roll()

*        display total

*        if total = 7 or total = 11 then

*            return 1

*        else if total = 2 or total = 3 or total = 12 then

*            return 0

*        else

*            return call point(total)

*        endif

*

* point(p)

*        output p

*        results = roll

*        output results

*        repeat

*            if results = p then

*                return 1

*            else if results is 7 then

*                return 0

*            else  

*                pause

*                results = roll

*                output results

*            endif

*        while true

*

*

* roll (none)

*        d1 becomes random number between 1 and 6

*        call displayRoll with d1

*        d2 becomes random number between 1 and 6

*        call displayRoll with d2

*        return d1 + d2

*

* displayRoll (roll)

*        switch on roll

*            for each case 1 to 6 display dots

*/

  

public static int roll(){

       int d1=0,d2=0;

       // finish this method

       Random rand = new Random();

       d1 = rand.nextInt(6)+1;

       displayRoll(d1);

       d2 = rand.nextInt(6)+1;

       displayRoll(d2);

       return d1 + d2;

   }

  

   public static void displayRoll(int r){

       switch(r){

       case 1:

           System.out.println();

           System.out.println(" *");

           System.out.println();

           break;

       case 2:

           System.out.println();

           System.out.println("*");

           System.out.println();

           System.out.println(" *");

           System.out.println();

           break;

       case 3:

           System.out.println();

           System.out.println("*");

           System.out.println();

           System.out.println(" *");

           System.out.println();

           System.out.println("*");

           System.out.println();

           break;

       case 4:

           System.out.println();

           System.out.println("*");

           System.out.println();

           System.out.println(" *");

           System.out.println();

           System.out.println("*");

           System.out.println();

           System.out.println(" *");

           System.out.println();

           break;

       case 5:

           System.out.println();

           System.out.println("*");

           System.out.println();

           System.out.println(" *");

           System.out.println();

           System.out.println("*");

           System.out.println();

           System.out.println(" *");

           System.out.println();

           System.out.println("*");

           System.out.println();

           break;      

       case 6:

           System.out.println();

           System.out.println("*");

           System.out.println();

           System.out.println(" *");

           System.out.println();

           System.out.println("*");

           System.out.println();

           System.out.println(" *");

           System.out.println();

           System.out.println("*");

           System.out.println();

           System.out.println(" *");

           System.out.println();

           break;

          

Explanation / Answer

/////////////////////////////////Craps.java//////////////////////
import java.util.Random;
import java.util.Scanner;
public class Craps {
public static int play(){
int total = roll();
System.out.println("The total you got after Rolling: "+total);
if (total ==7 || total == 11) return 1;
else if (total ==2 ||total == 3 || total == 12 ) return 0;
else return point(total);
}
public static int point(int total) {
System.out.println("Again Rolling.......");
int results = roll();
while(1>0){
if(results==total){
return 1;
}
else if(results==7){
return 0;
}
else{
System.out.println("Again Rolling.......");
results = roll();
}
}
}
public static int roll(){
Random rand = new Random();
int d1 = rand.nextInt(6);
if(d1==0) d1=d1+1;
System.out.println("Dice-1 Value:"+d1);
displayRoll(d1);
int d2 = rand.nextInt(6);
if(d2==0) d2=d2+1;
System.out.println("Dice-2 Value:"+d2);
displayRoll(d2);
return d1+d2;
}
public static void displayRoll(int value) {
switch(value){
case 1:
System.out.println();
System.out.println(" *");
System.out.println();
break;
case 2:
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
break;
case 3:
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
System.out.println("*");
System.out.println();
break;
case 4:
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
break;
case 5:
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
System.out.println("*");
System.out.println();
break;   
case 6:
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
break;
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(1>0){
System.out.println("Press 'y' to play......Press 'n' to exit:");
String input = sc.next();
System.out.println(input);
if(input.equalsIgnoreCase("y")){
System.out.println("Your Game Starts:");
int results = play();
if(results==1){
System.out.println("Hurray...You won the game :)");
}
else{
System.out.println("Opps......You Lose the Game");
}
}
else if(input.equalsIgnoreCase("n")){
System.out.println("Bye...Bye...");
break;
}
}
}
}

Note:please find the code as per your requirement.....if any queries or doubts please ping me........Happy coding

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote