Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

So I'm trying to get a small straight that have Four sequential dice (1-2-3-4, 2-3-4-5, or 3-4-5-6), Large straight with Five sequential dice (1-2-3-4-5 or

So I'm trying to get a small straight that have Four sequential dice (1-2-3-4, 2-3-4-5, or 3-4-5-6), Large straight with Five sequential dice (1-2-3-4-5 or 2-3-4-5-6),Three of a kind with three or more dice with the same number, Four of a kind with four or more dice. So far I made the program work to getting a full house I just need help getting the others.

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");

}

}

These are the results:

Testing Die Object

d1 face value is: 2

rolling d1 5 times

4

2

3

1

4

End of Die Testing

Testing Cup Object

Displaying original values of dice in cup

5

1

2

4

6

Testing roll and display of new values

3

3

3

6

6

Testing is it a full house

true

End of Cup Testing

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions