Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

More Books

Students also viewed these Databases questions

Question

???? Describe the importance of a well-functioning financial system

Answered: 1 week ago

Question

How would you assess the value of an approach like this?

Answered: 1 week ago

Question

When would you use one approach, and when would you use another?

Answered: 1 week ago

Question

3. How would this philosophy fit in your organization?

Answered: 1 week ago