'F' → Fullscreen
rollDie() that prints the die result. main(). import java.util.Scanner;
public class Program{ public static void main(String[] args) { System.out.println("--- CRAPS ---"); // Call several times to verify randomness rollDie(); rollDie(); rollDie(); }
// Step 1: print the die result (no return yet) static void rollDie() { int die = (int)(Math.random() * 6) + 1; System.out.println("Rolled: " + die); }}rollDie() to return the value. main() after the call. import java.util.Scanner;
public class Program{ public static void main(String[] args) { System.out.println("--- CRAPS ---");
int d1 = rollDie(); int d2 = rollDie(); System.out.println("You rolled: " + d1 + " and " + d2); }
// Step 2: now return the value instead of printing static int rollDie() { return (int)(Math.random() * 6) + 1; }}rollDice() that calls rollDie() twice, prints the breakdown, and returns the total. promptRoll() for user input. import java.util.Scanner;
public class Program{ public static void main(String[] args) { System.out.println("--- CRAPS ---"); promptRoll(); int total = rollDice(); System.out.println("Total: " + total); // Test variable for correctness }
static int rollDie() { return (int)(Math.random() * 6) + 1; }
// Step 3: compose method to roll two dice static int rollDice() { int die1 = rollDie(); int die2 = rollDie(); int total = die1 + die2; System.out.println("You rolled " + die1 + " + " + die2 + " = " + total); return total; }
// Roll dice input static void promptRoll() { Scanner input = new Scanner(System.in); System.out.print("Press Enter to roll..."); input.nextLine(); // simple pause }}evaluateComeOutRoll(int roll) to print the outcome and return whether the round is over. point = roll. import java.util.Scanner;
public class Program{ public static void main(String[] args) { System.out.println("--- CRAPS ---"); int point = 0;
promptRoll(); int roll = rollDice(); boolean roundOver = evaluateComeOutRoll(roll);
if (!roundOver) { point = roll; System.out.println("The point is now " + point + "."); // Next task: loop while not over and resolve the point. } }
static int rollDie() { return (int)(Math.random() * 6) + 1; }
static int rollDice() {5 collapsed lines
int d1 = rollDie(); int d2 = rollDie(); int total = d1 + d2; System.out.println("You rolled " + d1 + " + " + d2 + " = " + total); return total; }
static void promptRoll() {3 collapsed lines
Scanner input = new Scanner(System.in); System.out.print("Press Enter to roll..."); input.nextLine(); // simple pause }
// Step 4: come-out evaluation static boolean evaluateComeOutRoll(int roll) { if (roll == 7 || roll == 11) { System.out.println("Rolled a " + roll + "! You win!"); return true; } else if (roll == 2 || roll == 3 || roll == 12) { System.out.println("Rolled a " + roll + ". You lose."); return true; } else { System.out.println("Rolled a " + roll + "."); return false; } }}evaluatePointRoll(int roll, int point) and loop until win/lose. import java.util.Scanner;
public class Program{ public static void main(String[] args) { System.out.println("--- CRAPS ---");
int point = 0; boolean gameOver;
promptRoll(); int roll = rollDice(); gameOver = evaluateComeOutRoll(roll);
if (!gameOver) { point = roll; System.out.println("The point is now " + point + ".");
// Step 5: keep rolling until win (hit point) or lose (7) while (!gameOver) { promptRoll(); roll = rollDice(); gameOver = evaluatePointRoll(roll, point); } }
System.out.println("Thanks for playing!"); }
static int rollDie() { return (int)(Math.random() * 6) + 1; }
static int rollDice() {5 collapsed lines
int d1 = rollDie(); int d2 = rollDie(); int total = d1 + d2; System.out.println("You rolled " + d1 + " + " + d2 + " = " + total); return total; }
static void promptRoll() {3 collapsed lines
Scanner input = new Scanner(System.in); System.out.print("Press Enter to roll..."); input.nextLine(); // simple pause }
static boolean evaluateComeOutRoll(int roll) {15 collapsed lines
if (roll == 7 || roll == 11) { System.out.println("Rolled a " + roll + "! You win!"); return true; } else if (roll == 2 || roll == 3 || roll == 12) { System.out.println("Rolled a " + roll + ". You lose."); return true; } else { System.out.println("Rolled a " + roll + "."); return false; } }
// Step 5: resolve after point is set static boolean evaluatePointRoll(int roll, int point) { if (roll == point) { System.out.println("Rolled a " + roll + "! You win!"); return true; } else if (roll == 7) { System.out.println("Rolled a 7. You lose."); return true; } else { System.out.println("Rolled a " + roll + ". Still shooting for " + point + "."); return false; } }}--- CRAPS ---Press Enter to roll...You rolled 4 + 3 = 7Rolled a 7! You win!Thanks for playing!main() focus on now?Submit your completed .java file and reflection answers to the appropriate dropbox.