Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

So in my CS class we have to model playing cards with the classes hand, deck, and card. I got the card class done and

So in my CS class we have to model playing cards with the classes hand, deck, and card. I got the card class done and the majority of the deck and hand class, however I'm getting a little lost on how to finish them up. The link to what my professor wants it to be like is https://cs.uwlax.edu/~jmaraist/120-spring-2017/2017/04/11/cs120-project-4/ . My code so far is:

public class Card { public static final byte CLUB=0; public static final byte DIAMOND=1; public static final byte HEART=2; public static final byte SPADE=3; public static final int Jack = 11; public static final int Queen = 12; public static final int King = 13; public static final int Ace = 14; private final byte suit; private final byte rank; public Card(final byte suit, final byte rank) { this.rank = rank; this.suit = suit; }

public byte getSuit() { return suit; }

public byte getRank() { return rank; } public String suitAsString() { //returns the name for each suit switch ( suit ) { case SPADE: return "Spades"; case HEART: return "Hearts"; case DIAMOND: return "Diamonds"; case CLUB: return "Clubs"; default: return ""; } } public String rankAsString() { //returns the name for each rank switch (rank){ case 1: return ""; case 2: return "Two"; case 3: return "Three"; case 4: return "Four"; case 5: return "Five"; case 6: return "Six"; case 7: return "Seven"; case 8: return "Eight"; case 9: return "Nine"; case 10: return "Ten"; case 11: return "Jack"; case 12: return "Queen"; case 13: return "King"; case 14: return "Ace"; default: return ""; } } public String toString(){ //Method that returns the cards suit and rank in English return rankAsString() + " of " + suitAsString(); } }

import java.util.Random; import java.util.ArrayList;

public class Deck { private static ArrayList discarded; //ArrayList that stores the cards in the discard pile private static ArrayList unused; //ArrayList that stores the remaining cards in the deck private static ArrayList hand; //ArrayList that stores the number of hands private static int cards; //Declares a private global variable "cards" private static int hands; //Declares a private global variable "hands3" public Deck() { discarded = new ArrayList<>(); unused = new ArrayList(); hand = new ArrayList<>(); for(byte suit = 0; suit <= 3; suit++){ //Adds the unused cards to the ArrayList unused for(byte rank = 2; rank <= 14 && rank >=2; rank++){ unused.add(new Card(suit, rank)); } } shuffle(); //Makes a call to the Method shuffle() to shuffle the deck(called unused in this case) } public void shuffle() { //Method that shuffles the deck of cards for(int i = unused.size()-1; i > 0; i--){ int random = (int) (Math.random()*(i+1)); unused[random] = unused[i]; } } public Card[] getUnused() { //Method that gives the amount of cards in the deck Card[] cards2 = new Card[unused.size()]; return unused.toArray(cards2); } public Card[] getDiscarded() { //Method that gives the amount of cards in the discard pile Card[] cards1 = new Card[discarded.size()]; return discarded.toArray(cards1); } public void deal(final int hands, final int cards) { this.hands = hands; this.cards = cards; //check if enough cards /*hands.add(new Hand(Hand this, new ArrayList())); //have to do this h times * for (i

import java.util.ArrayList;

public class Hand { private static ArrayList handOfCards; //Declares a private global ArrayList public static Deck deck; //Declares a public global Deck "deck" public Hand(final Deck d, ArrayList handOfCards) { this.handOfCards = handOfCards; this.deck = deck; } public Deck getDeck(Deck deck) { return deck; } // public Card[] getCards() { // Card[] c = new Card[handOfCards.size()]; // return handOfCards.toArray(c); // } public void playCard(final Card card) { //Method takes one card from the hand put it in the discard pile } public ArrayList getCards() { return handOfCards; } public void discardHand() { //Method takes all the cards in the hand and puts it in the discard pile } public static void main(String[] args) {

}

}

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

Online Market Research Cost Effective Searching Of The Internet And Online Databases

Authors: John F. Lescher

1st Edition

0201489295, 978-0201489293

More Books

Students also viewed these Databases questions

Question

Differentiate between hard and soft measures of service quality.

Answered: 1 week ago

Question

Be familiar with the different perspectives of service quality.

Answered: 1 week ago