Question: How would my UML look using these classes? I'll also include the basic UML that it'd look like. import java.util.Random; public class Die { private

How would my UML look using these classes? I'll also include the basic UML that it'd look like.How would my UML look using these classes? I'll also include the

import java.util.Random;

public class Die {

private int dieFaces, minimum;

private int[] results;

public Die() {

this(6, 1);

results = new int[dieFaces];

results[0] = minimum;

results[1] = 2;

results[2] = 3;

results[3] = 4;

results[4] = 5;

results[5] = 6;

}

public Die(int[] outcomes) {

results = outcomes;

}

public Die(int sides, int min) {

dieFaces = sides;

minimum = min;

}

public int nextRoll() {

Random rand = new Random();

return results[rand.nextInt(results.length)];

}

}

-----------------------------------------------------------------------------------

public class HoldAt20PigPlayer implements PigPlayer {

public boolean isRolling(int myScore, int otherScore, int turnTotal) {

return ((turnTotal

}

}

---------------------------------------------------------------

import java.util.*;

public class OOPig {

public static void main (String[] args) {

PigPlayer playerOne, playerTwo;

Random rand = new Random();

int num = rand.nextInt(2);

if(num == 0) {

System.out.println("You will be player 1.");

playerOne = new UserPigPlayer();

playerTwo = new HoldAt20PigPlayer();

}

else {

System.out.println("You will be player 2.");

playerTwo = new UserPigPlayer();

playerOne = new HoldAt20PigPlayer();

}

PigGame game = new PigGame(playerOne, playerTwo);

game.play();

}

}

----------------------------------------------------------

public class PigGame {

public static final int GOAL_SCORE = 100;

private PigPlayer playerOne, playerTwo;

public PigGame() {

UserPigPlayer playerOne = new UserPigPlayer();

UserPigPlayer playerTwo = new UserPigPlayer();

}

public PigGame(PigPlayer player1, PigPlayer player2) {

playerOne = player1;

playerTwo = player2;

}

public void play() {

int playOneScore = 0, playTwoScore = 0, turnTotal1 = 0, turnTotal2 = 0;

Die die = new Die();

while(playOneScore

System.out.println("Player 1 score: " + playOneScore);

System.out.println("Player 2 score: " + playTwoScore);

System.out.println("It is player 1's turn.");

while(playerOne.isRolling(playOneScore, playTwoScore, turnTotal1)) {

int roll = die.nextRoll();

System.out.println("Roll: " + roll);

if(roll >= 2 && roll

turnTotal1 += roll;

continue;

}

else if(roll == 1) {

turnTotal1 = 0;

break;

}

}

playOneScore += turnTotal1;

System.out.println("New Score: " + playOneScore);

turnTotal1 = 0;

if(playOneScore >= GOAL_SCORE) {

break;

}

System.out.println("Player 1 score: " + playOneScore);

System.out.println("Player 2 score: " + playTwoScore);

System.out.println("It is player 2's turn.");

while(playerTwo.isRolling(playTwoScore, playOneScore, turnTotal2)) {

int roll = die.nextRoll();

System.out.println("Roll: " + roll);

if(roll >= 2 && roll

turnTotal2 += roll;

continue;

}

else if(roll == 1) {

turnTotal2 = 0;

break;

}

}

playTwoScore += turnTotal2;

System.out.println("New Score: " + playTwoScore);

turnTotal2 = 0;

}

}

}

----------------------------------------------------------------------

public interface PigPlayer {

boolean isRolling(int myScore, int otherScore, int turnTotal);

}

----------------------------------------------

import java.util.*;

public class UserPigPlayer implements PigPlayer {

public UserPigPlayer() {

System.out.println("Press Enter to roll; enter anything to hold.");

}

public boolean isRolling(int myScore, int otherScore, int turnTotal) {

String input;

Scanner keyboard = new Scanner(System.in);

System.out.print("Turn total: " + turnTotal + " " + "Roll/Hold? ");

input = keyboard.nextLine();

return (input.equals(""));

}

}

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!