Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.util.Objects; import java.util.Scanner; public class Dice { public String roll() { return null; } public static void main(String[] args) { // user input is
import java.util.Objects; import java.util.Scanner; public class Dice { public String roll() { return null; } public static void main(String[] args) { // user input is stored into "input" Scanner input = new Scanner(System.in); // variable named "username" String username; System.out.println("Please enter your name: "); // The input is assigned to "username" variable username = input.nextLine(); do { Dice_class die1 = new Dice_class(6); Dice_class die2 = new Dice_class(); // Variable named "sum" is storing the sum of both dies. int sum1; sum1 = die1.roll() + die2.roll(); // array with all the possible outcomes int[] outcomes = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; // if the outcome is 2,3, or 12,the message will be printed out if (sum1 == 2 || sum1 == 3 || sum1 == 12) { // System.out.println(username + " you lost"); } // if the sum is either 7 or 11, the player wins if (sum1 == 7 || sum1 == 11) { System.out.println(username + " YOU WIN"); // if any other number is printed as shown the player is still in the game. } else if (sum1 == 4 || sum1 == 5 || sum1 == 6 || sum1 == 8 || sum1 == 9 || sum1 == 10) ; { System.out.println("You are still in the game " + username); System.out.println("Please enter Yes to continue"); input.nextLine(); } } while (input.equals("Yes")); } }
For any other score (4, 5, 6, 8, 9, 10), the number is remembered and the player must continue rolling the dice until either a. A sum of seven is rolled (in which case the player loses). b. The initial number is achieved (in which case the player wins.
Can someone please help me implement this in java? I also created a class called Dice_class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started