Question: //DieGame.java import java.util.*; public class DieGame { private final int TOTAL_SIDES = 6; private int diceValue; DieGame() { rollDice(); } public void rollDice() { Random

//DieGame.java import java.util.*;

public class DieGame {

private final int TOTAL_SIDES = 6; private int diceValue;

DieGame() { rollDice(); }

public void rollDice() { Random r = new Random(); diceValue = r.nextInt(TOTAL_SIDES) + 1; }

public int getdiceValue() { return diceValue; }

public static int getRolldiceValue() {

DieGame d = new DieGame(); int roll1diceValue = d.getdiceValue(); d.rollDice(); int roll2diceValue = d.getdiceValue();

return (roll1diceValue + roll2diceValue); }

public static boolean checkLimit(int diceValue) {

if (diceValue > 21) return false; else return true; }

public static boolean againPlay() {

Scanner scan = new Scanner(System.in); System.out.print("Roll the dice? (y/n) : "); String userResponse = scan.nextLine(); char choice = userResponse.charAt(0);

if (choice == 'Y' || choice == 'y') return true; else return false; }

public static void printResults(int c_poinys, int p_points) {

System.out.println(" Game Over "); System.out.println("Player Points: " + p_points); System.out.println("Computer Points: " + c_poinys);

if (p_points > c_poinys && checkLimit(p_points)) { System.out.println("You win!"); } else if (checkLimit(p_points) && !checkLimit(c_poinys)) { System.out.println("You win!"); } else if (p_points == 21 && c_poinys != 21) { System.out.println("You win!"); } else if (p_points == c_poinys) { System.out.println("Game Tie !"); } else if (!checkLimit(p_points)&& !checkLimit(c_poinys)) { System.out.println("No Winner"); } else { System.out.println("Computer wins!"); }

}

public static void main(String[] args) {

int comp_Points = 0; int player_Points = 0;

while (againPlay() == true) {

comp_Points = comp_Points + getRolldiceValue(); player_Points = player_Points + getRolldiceValue();

if (!checkLimit(player_Points)|| !checkLimit(comp_Points)) { break; }

System.out.println("Player Points: " + player_Points); }

if (player_Points == 0 && comp_Points == 0) System.out.println("No play, No win!!!"); else printResults(comp_Points, player_Points); }

}

HOW DO YOU SEPERATE THIS SOURCE CODE TO MAKE TWO CODE. ONE WITH DIE AND DIEDEMO SHOWING THE RELATIONSHIP OF BOTH ONLY ONE SHOULD OUTPUT USING BLUE J

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!