Question: We created a Die object and a Cup object in java. We determined if a Full House had been rolled. Starting from the code we

We created a Die object and a Cup object in java. We determined if a Full House had been rolled. Starting from the code we developed , determine if a player has rolled Three of a Kind, Four of a Kind, Small straight, Large straight.

This is the code I have so far.

public class Cup

{

private Die[] dice = new Die[5];

private void fillCupWithDice()

{

for(int x = 0; x<5; x++)

{

dice[x] = new Die();

}

}

public void roll()

{

for(int x = 0; x < 5; x++)

{

dice[x].roll();

}

}

public Cup()

{

fillCupWithDice();

for(int x = 0; x< 5; x++)

{

dice[x].roll();

}

}

public void showDice()

{

for(int x = 0; x< 5; x++)

{

System.out.println(dice[x].getFaceValue());

}

}

public boolean isFullHouse()

{

int counters[] = {0,0,0,0,0,0,0};// ignore location[0] there are 6

for(int x = 0; x < 5; x++)

{

counters[dice[x].getFaceValue()]++;

}

boolean threeCount = false;

boolean twoCount = false;

for(int x = 1; x <7; x++)

{

if (counters [x] == 3) threeCount = true;

if (counters[x] == 2) twoCount = true;

}

return threeCount &&twoCount;

}

}

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

public class TestObject {

public static void main(String[] args)

{

System.out.println("Testing Die Object");

Die d1 = new Die();

System.out.println("d1 face value is: " +d1.getFaceValue());

System.out.println(" rolling d1 5 times");

for(int x = 0; x < 5; x++)

{

d1.roll();

System.out.println(d1.getFaceValue());

}

System.out.println("End of Die Testing");

System.out.println(" Testing Cup Object");

Cup c1 = new Cup();

System.out.println("Displaying original values of dice in cup");

c1.showDice();

System.out.println("Testing roll and display of new values");

c1.roll();

c1.showDice();

System.out.println(" Testing is it a full house");

System.out.println(c1.isFullHouse());

System.out.println("End of Cup Testing");

}

}

Results

Testing Die Object

d1 face value is: 3

rolling d1 5 times

2

1

2

1

1

End of Die Testing

Testing Cup Object

Displaying original values of dice in cup

6

4

6

1

2

Testing roll and display of new values

4

3

5

4

3

Testing is it a full house

false

End of Cup Testing

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!