C Seana ttps//blackboard towson.edu/webapps/assessment/take/launchjsp course ass
ID: 3587158 • Letter: C
Question
C Seana ttps//blackboard towson.edu/webapps/assessment/take/launchjsp course assessment jd naining Time: 37 minutes, 30 seconds estion Completion Status: QUESTION 3 3. Programming Write a complete program that plays a single game of craps, displays the individual rolls and reports when a game is LOST or WON and shows the number of roils used by the game. The algorithm is as follows Simulate the soll of 2 dice wsing a JAVA random somber generator. . Record the som of this first roll as the game point and print out: Game point point ctab (if) the gaese poiest is 7 or 11 print out Game won an toll (else) contisue solling the dice. After each roll, print Croll-value-abs (f) a tollether 7 11 prist out Game lost in Croll count solls Sorry. * (else in) a roll equal the game poimt print out: Game won in Groll-coust solls Congratlations Otberwise, repeat step4 TTTAriai Click Save and Submit to save and submit Click Save All Answers to save an DELLExplanation / Answer
import java.io.*;
import java.util.*;
public class DemoGame2{
public static void main(String[] args){
Random rand = new Random();
int d1 = rand.nextInt(6) + 1;
int d2 = rand.nextInt(6) + 1;
int game_point = d1+d2;
System.out.println("Game point : " + (d1+d2));
d1 = rand.nextInt(6) + 1;
d2 = rand.nextInt(6) + 1;
if (d1+d2 == 7 || d1+d2 == 11){
System.out.println("Game won in 1 roll");
}
else{
int count = 2;
while(true){
d1 = rand.nextInt(6) + 1;
d2 = rand.nextInt(6) + 1;
System.out.println("Roll value :" + (d1+d2));
if (d1+d2 == 7 || d1+d2 == 11){
System.out.println("Game lost in " + count + " rolls. Sorry");
break;
}
else{
if (d1+d2 == game_point){
System.out.println("Game won in " + count + " rolls. Congratulations!");
break;
}
}
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.