Question

Can someone help me with this in Java? For this activity, you will be creating all...

Can someone help me with this in Java?

For this activity, you will be creating all of the Java classes you feel necessary to appropriately model a playing card shoe. A card shoe is a device that starts with multiple decks of cards combined and shuffled into one unit, and then cards can be drawn one at a time out of the shoe. For our game, let’s assume that we use the same shoe indefinitely, and that we can “reshuffle” the shoe which will reset it to containing as many decks as it did initially, again in a new shuffled order.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

solution:

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

public class Card

{

int rank;

Suit suit;

public Card(int rank, Suit suit)

{

this.rank=rank;

this.suit=suit;

}

public int getRank()

{
return rank;
}


public void setRank(int rank)
{
if (rank < 1 || rank > 13)
{
   System.out.println("rank invalid");
}
  
else
{
this.rank = rank;
  
}
}

  
public Suit getSuit()
{
return suit;
}

  
public void setSuit(Suit suit)
{
if (suit == null)

{
  

   System.out.println("suit invalid");

  
  
}
else
{

this.suit = suit;

}
}

@Override
public String toString()
{
return String.format("%s[rank=%d, suit=%s]",
getClass().getSimpleName(),
getRank(),
getSuit().name());
}
public enum Suit
{
SPADES, HEARTS, DIAMONDS, CLUBS;
}
  
}

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


import java.util.Random;


public class Deck
{
Card[] cards;
int max;


public Deck()
{
cards = new Card[52];
populate();
}


public void populate()
{
Card.Suit[] suits = new Card.Suit[4];
  

int index = 0;
for (Card.Suit s : suits)
{
   for (int r = 1; r <= 13; r++)
   { index++;
   cards[index] = new Card(r, s);
}
  
}
max = cards.length - 1;
assert cards[max] != null;
}


public void shuffle()
{

Random random = new Random();

for (int p = cards.length - 1; p > 0; p--) {
int q = random.nextInt(p + 1);
Card temp_card = cards[q];
cards[q] = cards[p];
cards[p] = temp_card;
  
  
}
}

public boolean empty()
{
return max < 0;
}

public Card useCard()
{
if (empty())
  
{
   throw new IllegalArgumentException("Can't deal from an empty deck.");
  
}
   return cards[max--];
}

  
public void outputDeck()
{
if (empty()) {
System.out.println("The deck is empty.");
return;
}

System.out.println("The current deck:");
for (Card card : cards)
System.out.println(" " + card);
}


}

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

import java.util.ArrayList;
import java.util.Collections;

public class Shoe {
private ArrayList<Card> BjShoe = new ArrayList<>();
int n;
  
  

public Shoe(int n) {
   this.n=n;
for (int i = 0; i < n; i++) {
addDeckToShoe(new Deck());
}
}


public void reshuffleShoe()
{
   for (int i = 0; i < n; i++) {
addDeckToShoe(new Deck());
}
  
   this.shuffleShoe();
  
}
private void addDeckToShoe(Deck d) {
for (int i = 0; i < 52; i++) {
BjShoe.add(d.useCard());
}
}

  
public void shuffleShoe() {
Collections.shuffle(BjShoe);
}


public Card use_Card() {
Card card = BjShoe.get(BjShoe.size() - 1); // last card in the shoe
BjShoe.remove(card);
return card;
}

public int leftCards() {
return BjShoe.size();
}
}

please give me thumb up

Add a comment
Know the answer?
Add Answer to:
Can someone help me with this in Java? For this activity, you will be creating all...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • hello there, i have to implement this on java processing. can someone please help me regarding...

    hello there, i have to implement this on java processing. can someone please help me regarding that? thanks War is the name of a popular children’s card game. There are many variants. After playing War with a friend for over an hour, they argue that this game must never end . However! You are convinced that it will end. As a budding computer scientist, you decide to build a simulator to find out for sure! You will implement the logic...

  • Intro to Java. Can someone please help me answer this question. Create a java program playing...

    Intro to Java. Can someone please help me answer this question. Create a java program playing the game of craps with a random number generator. Write a method craps that plays the game of craps and it should return a 1 representing a win, a 2 representing a loss, and a 0 representing the need to toss the pair of dice again. The main method should ask how many games you wish to play then call the method craps. Main...

  • I am just curious about this question... please can you answer with applying indent and space...

    I am just curious about this question... please can you answer with applying indent and space clearly. Furthermore, can you make answer shortly as possible..? This is a python question Question 6.34 The two-player card game war is played with a standard deck of 52 cards. A shuffled deck is evenly split among the two players who keep their decks face-down. The game consists of battles until one of the players runs out of cards. In a battle, each player...

  • Using Java You are helping a corporation create a new system for keeping track of casinos...

    Using Java You are helping a corporation create a new system for keeping track of casinos and customers. The system will be able to record and modify customer and casino information. It will also be able to simulate games in the casino. Customer-specific requirements You can create new customers All new customers have a new customerID assigned to them, starting with 1 for the first, 2 for the second, 3 for the third, ect. New customers have names and monetary...

  • While using JAVA , solve this. There are three basic classes we'll need this week: Card:...

    While using JAVA , solve this. There are three basic classes we'll need this week: Card: A class like the one presented in the modules, but with a few changes. Hand: A class that represents the cards held by a single player. Deck: A class that represents the source of the cards for dealing and, as the game progresses, the place from which players can receive new cards (say, as they pick cards "from the deck" or when future hands...

  • Can someone help me on this assignment, please? Thank you. Locate a product, treatment, or device...

    Can someone help me on this assignment, please? Thank you. Locate a product, treatment, or device that has been systematically reviewed such as a water flosser, ultrasonic scaler, Airflow, and write a one-page description of what you find along with a picture of the product, device, or treatment. Are the conclusions drawn appropriate? What are the flaws?  

  • can someone help me with this C++ problem write your game() function and 3+ functions that...

    can someone help me with this C++ problem write your game() function and 3+ functions that simulate the game of Jeopardy Dice according to the following game mechanics and specifications. Game Mechanics There are two players: the user and the computer, who alternate turns until one of them reaches 80 points or higher. The user is always the first player and starts the game. If any player reaches 80 points or more at the end of their turn, the game...

  • ----Can someone please help me solve this one using JAVA ----I thank you in advance Create...

    ----Can someone please help me solve this one using JAVA ----I thank you in advance Create an application that reads an HTML file and converts it to plain text. HTML Converter INPUT <h1>Grocery List</h1> <ul>     <li>Eggs</li>     <li>Milk</li>     <li>Butter</li> </ul> OUTPUT Grocery List * Eggs * Milk * Butter

  • Can someone please help me with the following java assignment. So in this assignment you will...

    Can someone please help me with the following java assignment. So in this assignment you will begin with the starterProject I provide and then add to it.  I am also asking that before you begin you really look at the starterProject because this is the object-oriented basics. The starterProject is the exact same as the ClassClockExample.zip in Module 5.  I’ve also done this using a clock because it is something that you already know how it works.  Remember that OOD and OOP is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT