Question

CARD GAME (LINKING AND SORTING) DATA STRUCTURES TOPIC(S) Topic Primary Linked lists Sorting Searching Iterators As needed Rec

CARD UML class Diagram 1. Write a Card class to represent a playing card. Card - face : String - suit : String PILE (OF CARDS

Figure 1 - Illustration of a Pile with 3 linked cards. C. Include methods that represent operations on piles of cards that yo

a. -above : Card Include instance variables above and below of type Card to hold references to the cards before and after the

PLAYER 1. Write a Player class. a. Include instance variables related to players, such as i. name and/or ID ii. hand - instan

GOOD PROGRAMMING PRACTICES Classes • Make instance variables private Make methods public and include (almost always) o Constr

RUBRIC Requirement Card class (with above and below...) Pile class (with topCard, bottomCard, sorting, shuffling...) Deck (ex

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

class Card
{
//public static enum Face {Ace, Deuce, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King};
public static enum Face {Ace(1), King(2), Queen(3), Jack(4), Ten(5), Nine(6), Eight(7), Seven(8), Six(9), Five(10), Four(11), Three(12), Deuce(13);
int rank;
Face(int r){ rank = r;}
int getRank() {return rank;}
}
//public static enum Suit {Clubs, Diamonds, Hearts, Spades };
public static enum Suit {Spades(1), Hearts(2), Diamonds(3), Clubs(4);
int order;
Suit(int o){ order = o;}
int getOrder() {return order;}
}

private final Face face; // face of card
private final Suit suit; // suit of card

// two-argument constructor
public Card( Face cardFace, Suit cardSuit )
{   
face = cardFace; // initialize face of card
suit = cardSuit; // initialize suit of card
}

// return face of the card
public Face getFace() { return face;}

// return suit of Card
public Suit getSuit() { return suit;}

// return String representation of Card
public String toString()
{
//return String.format( "%s.%s", suit.getOrder(), face.getRank() );
return String.format( "%s.%s", suit, face );
}
}

// class DeckOfCards declaration
public class DeckOfCards
{
private List< Card > list; // declare List that will store Cards

// set up deck of Cards and shuffle
public DeckOfCards()
{
Card[] deck = new Card[ 52 ];
int count = 0; // number of cards

// populate deck with Card objects
for ( Card.Suit suit : Card.Suit.values() )
{
for ( Card.Face face : Card.Face.values() )   
{
deck[ count ] = new Card( face.getRank(), suit.getOrder() );
count++;
}
}

list = Arrays.asList( deck ); // get List
//Collections.shuffle( list ); // shuffle deck
}

// output deck
public void printCards()
{
// display 52 cards in two columns
for ( int i = 0; i < list.size(); i++ )
System.out.printf( "%-20s%s", list.get( i ),
( ( i + 1 ) % 2 == 0 ) ? "\n" : "" );
}

public static void main( String[] args )
{
DeckOfCards cards = new DeckOfCards();
cards.printCards();
//cards.InsertionSort();
}
}


//Insertion Sort

public static void insertionSort(DeckOfCards[] listToSort)
{
for (int i = 0; i < listToSort.length-1; i++)
{
for (int k = i+1; k>0; k--)
{
if(listToSort[k] < listToSort[k-1]) //Code breaks here
{
swap(listToSort, k, k-1);
}
else
{
break;
}
print(listToSort);
}
}
}

Add a comment
Know the answer?
Add Answer to:
CARD GAME (LINKING AND SORTING) DATA STRUCTURES TOPIC(S) Topic Primary Linked lists Sorting Searching Iterators As...
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
  • using C++ // the Deck of the Card is for Go fish Card game Specification for...

    using C++ // the Deck of the Card is for Go fish Card game Specification for building your Deck For this part of your card game you will need to create a specification for your card deck. This specification will include functions for populating cards to your deck and shuffling the deck (randomizing the order of the cards). For the specification I do expect a list of each operation with preconditions and postconditions You must implement the code for your...

  • Program 4: C++ The Game of War The game of war is a card game played by children and budding comp...

    Program 4: C++ The Game of War The game of war is a card game played by children and budding computer scientists. From Wikipedia: The objective of the game is to win all cards [Source: Wikipedia]. There are different interpretations on how to play The Game of War, so we will specify our SMU rules below: 1) 52 cards are shuffled and split evenly amongst two players (26 each) a. The 26 cards are placed into a “to play” pile...

  • War—A Card game Playing cards are used in many computer games, including versions of such classic...

    War—A Card game Playing cards are used in many computer games, including versions of such classics as solitaire, hearts, and poker. War:    Deal two Cards—one for the computer and one for the player—and determine the higher card, then display a message indicating whether the cards are equal, the computer won, or the player won. (Playing cards are considered equal when they have the same value, no matter what their suit is.) For this game, assume the Ace (value 1) is...

  • using C++ // the Deck of the Card is for Go fish Card game Specification for building your Deck For this part of your ca...

    using C++ // the Deck of the Card is for Go fish Card game Specification for building your Deck For this part of your card game you will need to create a specification for your card deck. This specification will include functions for populating cards to your deck and shuffling the deck (randomizing the order of the cards). For the specification I do expect a list of each operation with preconditions and postconditions You must implement the code for your...

  • 2 A Game of UNO You are to develop an interactive game of UNO between a...

    2 A Game of UNO You are to develop an interactive game of UNO between a number of players. The gameplay for UNO is described at https://www.unorules.com/. Your program should operate as follows. 2.1 Setup 1. UNO cards are represented as variables of the following type: typedef struct card_s { char suit[7]; int value; char action[15]; struct card_s *pt; } card; You are allowed to add attributes to this definition, but not to remove any. You can represent colors by...

  • 2. Activity Directions: Create a UML diagram and then write the code for the object classes needed for your UNO game. You will need a minimum of three classes: a. A Card class (models an individual UN...

    2. Activity Directions: Create a UML diagram and then write the code for the object classes needed for your UNO game. You will need a minimum of three classes: a. A Card class (models an individual UNO card) b. A Hand class (models a player's hand) c. A Deck class (models the entire UNO deck) You may add other classes as you see fit. Test your program by writing a console application (a driver program) that creates a deck of...

  • For this project your card class must include an Image of the card. Here is a...

    For this project your card class must include an Image of the card. Here is a zip filecontaining 52 images you can use for your cards. Please note that the name for each card can be created by the concatenation of the first character of the suit, the value of the card, and the ".png" suffix. When you construct a card, you should have it load its image. Alternatives exist regarding how to draw() the card. One way to do...

  • Create a simplified Blackjack game using the Deck and Card classes (download the attached files to...

    Create a simplified Blackjack game using the Deck and Card classes (download the attached files to start).  There is also a "TestCard" class that creates a Deck and runs some simple code. You may choose to use this file to help you get started with your game program. 1) Deal 2 cards to the "player" and 2 cards to the "dealer".  Print both the player's cards, print one of the dealer's cards. Print the total value of the player's hand. 2) Ask...

  • Computer Science 182 Data Structures and Program Design Programming Project #3 – Link List Card Games...

    Computer Science 182 Data Structures and Program Design Programming Project #3 – Link List Card Games One of the nice things about Java is it is very easy to do fun things with graphics. The start code provided here will display a deck of cards on the screen and shuffle them. Your mission, is to start with this code and build a card game. Blackjack, poker solitaire, what ever your heart desires. Blackjack is the easiest. Obviously any program you...

  • Please to indent and follow structure!!!!! Assignment 3 - The card game: War Due Date: June...

    Please to indent and follow structure!!!!! Assignment 3 - The card game: War Due Date: June 9th, 2018 @ 23:55 Percentage overall grade: 5% Penalties: No late assignments allowed Maximum Marks: 10 Pedagogical Goal: Refresher of Python and hands-on experience with algorithm coding, input validation, exceptions, file reading, Queues, and data structures with encapsulation. The card game War is a card game that is played with a deck of 52 cards. The goal is to be the first player to...

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