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

The Game is called Twenty-One. The user rolls dice in an attempt to hit exactly

ID: 3776025 • Letter: T

Question

The Game is called Twenty-One.

          The user rolls dice in an attempt to hit exactly 21. If the user goes over 21, they lose. If they hit 21 exactly, they win. Pop upa message box that informs the user if they win or lose. Then they can play the game again if they want.

          At first the user should roll 2 dice. Once their total hits 15 or above, they should only roll one dice. (Use a random number generator to simulate the dice rolls.)

Build a GUI to display all the Game Data back to the user. Maybe include a roll button that the user can press to roll the dice. Also maybe include a button that says “Play Again”, that the user can press to play the game another time.

Explanation / Answer

public class Lab5 { public static void main(String[] args) { // TODO Auto-generated method stub //variables int dice1; int dice2; //Call the welcome method welcome(); //fetch random numbers /* * ************************************************************** *welcome method *welcome user *no parameters *no return **************************************************************** */ } public static void welcome() { System.out.println("Welcome to a Lucky (for me) Dice Game! FEELING LUCKY?!? Hope you brought lots of CASH!");{ } int dice1=(int)(Math.random()*6+1); int dice2=(int)(Math.random()*6+1); int sum= dice1 + dice2; System.out.println("Roll: total = " +sum); if (sum==2|| sum==3|| sum==12){ System.out.println("Sorry with a " + sum + " You LOSE :("); } else if(sum==7 || sum==11) { System.out.println("Woah!!! With a " + sum + " You WIN!!!!!!!"); } else{ if(sum==4 ||sum==5 ||sum==6 ||sum==8 ||sum==9 ||sum==10) dice1=(int)(Math.random()*6+1); dice2=(int)(Math.random()*6+1);} int roll2 = dice1 + dice2;} System.out.print("You rolled "+roll2+" ");{ while (roll2 !=7){ if (roll == roll2);{ System.out.println("You Win !"); break; }else{ } } }}

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