posted 4 years ago

The dice game Chicago has eleven rounds numbered 2 -12. In each round, the player tries to

roll and score the number of the round, the numbers being the possible combinations with 2

dice.

If a player throws the correct number for that round they score 1 point (e.g., if they roll a 4

and a 2 for round 6, they score a point). If they throw any other number they don’t score (e.g.

if they roll a 5 and a 3 for round 10, they do NOT score a point). The highest total after 11

rounds wins the game. If there is a tie for the highest score, then a winner cannot be

determined.

You will need to add two additional methods to the Chicago class called play and winner that are

implemented as follows:

Method play:

Return value: int (the number of points to add to the player’s score: 0 or 1)

Method name: play

Parameter list: one parameter – an integer representing the round number (i.e. int

roundNumber)

Algorithm: (determine number of points to add to current score)

-If the sum of FaceValue1 and FaceValue2 is equal to the roundNumber return 1

(a point is given)

-Otherwise, return 0 (no point is given)

Method winner:

-Return value: int (the number of the player who has the greatest score: 1, 2, 3, 4 for

player 1, player 2, player 3, and player 4, respectively. Return 0 if no player can be

determined)

-Method name: winner

-Parameter List: four parameters – four integers, one for each player's score

-Algorithm: determine which player number has won. The score must be greater than

all the other scores, NOT greater than or equal. For example, who wins if the following

is true?

Client Program PlayChicago.java:

Algorithm:

Create a for- loop that will iterate from 2 to 12 (the round number)

For each player, you will need to roll the dice and play this round by calling the

appropriate methods in Chicago. You will have 8 statements in this for-loop, 2

for each player. Also, remember to use your compound assignment operator.

Once rounds 2 through 12 are completed, call Chicago's winner method with

the four players' scores. The value returned is the player number of the winning

player. Note that if there’s a tie for the high score, then no winner is determined.

roll and score the number of the round, the numbers being the possible combinations with 2

dice.

If a player throws the correct number for that round they score 1 point (e.g., if they roll a 4

and a 2 for round 6, they score a point). If they throw any other number they don’t score (e.g.

if they roll a 5 and a 3 for round 10, they do NOT score a point). The highest total after 11

rounds wins the game. If there is a tie for the highest score, then a winner cannot be

determined.

You will need to add two additional methods to the Chicago class called play and winner that are

implemented as follows:

Method play:

Return value: int (the number of points to add to the player’s score: 0 or 1)

Method name: play

Parameter list: one parameter – an integer representing the round number (i.e. int

roundNumber)

Algorithm: (determine number of points to add to current score)

-If the sum of FaceValue1 and FaceValue2 is equal to the roundNumber return 1

(a point is given)

-Otherwise, return 0 (no point is given)

Method winner:

-Return value: int (the number of the player who has the greatest score: 1, 2, 3, 4 for

player 1, player 2, player 3, and player 4, respectively. Return 0 if no player can be

determined)

-Method name: winner

-Parameter List: four parameters – four integers, one for each player's score

-Algorithm: determine which player number has won. The score must be greater than

all the other scores, NOT greater than or equal. For example, who wins if the following

is true?

Client Program PlayChicago.java:

Algorithm:

Create a for- loop that will iterate from 2 to 12 (the round number)

For each player, you will need to roll the dice and play this round by calling the

appropriate methods in Chicago. You will have 8 statements in this for-loop, 2

for each player. Also, remember to use your compound assignment operator.

Once rounds 2 through 12 are completed, call Chicago's winner method with

the four players' scores. The value returned is the player number of the winning

player. Note that if there’s a tie for the high score, then no winner is determined.

Shaylen Patel

Greenhorn

Posts: 13

posted 4 years ago

this is what i have for playChicago

import java.util.*;

public class PlayChicago

{

public static void main(String [ ] args)

{

//Declare variables and instantiate objects

Chicago player1 = new Chicago();

Chicago player2 = new Chicago();

Chicago player3 = new Chicago();

Chicago player4 = new Chicago();

int p1=0, p2=0, p3=0, p4=0;

int playerWinner;

final int ROLLS = 6;

Die die1 = new Die();

Die die2 = new Die();

// Play Chicago

for(int roll = 1; roll <=ROLLS; roll++)

{

num1 = die1.roll();

num2 = die2.roll();

// Determine the winner

// Output the winner and scores

System.out.println("Player 1's score: " + p1 +

"\nPlayer 2's score: " + p2 +

"\nPlayer 3's score: " + p3 +

"\nPlayer 4's score: " + p4 + "\n");

if (playerWinner == 0)

System.out.println("A winner could not be determined");

else

System.out.println("Player " + playerWinner + " won!");

}

}

import java.util.*;

public class PlayChicago

{

public static void main(String [ ] args)

{

//Declare variables and instantiate objects

Chicago player1 = new Chicago();

Chicago player2 = new Chicago();

Chicago player3 = new Chicago();

Chicago player4 = new Chicago();

int p1=0, p2=0, p3=0, p4=0;

int playerWinner;

final int ROLLS = 6;

Die die1 = new Die();

Die die2 = new Die();

// Play Chicago

for(int roll = 1; roll <=ROLLS; roll++)

{

num1 = die1.roll();

num2 = die2.roll();

// Determine the winner

// Output the winner and scores

System.out.println("Player 1's score: " + p1 +

"\nPlayer 2's score: " + p2 +

"\nPlayer 3's score: " + p3 +

"\nPlayer 4's score: " + p4 + "\n");

if (playerWinner == 0)

System.out.println("A winner could not be determined");

else

System.out.println("Player " + playerWinner + " won!");

}

}

Shaylen Patel

Greenhorn

Posts: 13

posted 4 years ago

and this is the client program

public class Chicago

{

private final int MAX = 6; // maximum face value

private int faceValue1; // current value showing on the die

private int faceValue2;

//-----------------------------------------------------------------

// Constructor: sets the initial face value.

//-----------------------------------------------------------------

public Chicago()

{

faceValue1 = 0;

faceValue2 = 0;

}

//-----------------------------------------------------------------

// Rolls the die and returns the result.

//-----------------------------------------------------------------

public void roll()

{

faceValue1 = (int) (Math.random() * MAX) + 1;

faceValue2 = (int) (Math.random() * MAX) + 1;

}

//-----------------------------------------------------------------

// Face value mutator. The face value is not modified if the

// specified value is not valid.

//-----------------------------------------------------------------

public void setFaceValue (int value)

{

if (value > 0 && value <= MAX)

faceValue1 = value;

faceValue2 = value;

}

//-----------------------------------------------------------------

// Face value accessor.

//-----------------------------------------------------------------

public int getFaceValue1()

{

return faceValue1;

}

public int getFaceValue2()

{

return faceValue2;

}

//------------------------------------------------------------------

// Play method to determine if this player scores a point or not

//------------------------------------------------------------------

//------------------------------------------------------------------

// Winner method to determine who wins the game

//------------------------------------------------------------------

}

public class Chicago

{

private final int MAX = 6; // maximum face value

private int faceValue1; // current value showing on the die

private int faceValue2;

//-----------------------------------------------------------------

// Constructor: sets the initial face value.

//-----------------------------------------------------------------

public Chicago()

{

faceValue1 = 0;

faceValue2 = 0;

}

//-----------------------------------------------------------------

// Rolls the die and returns the result.

//-----------------------------------------------------------------

public void roll()

{

faceValue1 = (int) (Math.random() * MAX) + 1;

faceValue2 = (int) (Math.random() * MAX) + 1;

}

//-----------------------------------------------------------------

// Face value mutator. The face value is not modified if the

// specified value is not valid.

//-----------------------------------------------------------------

public void setFaceValue (int value)

{

if (value > 0 && value <= MAX)

faceValue1 = value;

faceValue2 = value;

}

//-----------------------------------------------------------------

// Face value accessor.

//-----------------------------------------------------------------

public int getFaceValue1()

{

return faceValue1;

}

public int getFaceValue2()

{

return faceValue2;

}

//------------------------------------------------------------------

// Play method to determine if this player scores a point or not

//------------------------------------------------------------------

//------------------------------------------------------------------

// Winner method to determine who wins the game

//------------------------------------------------------------------

}