Question

Deck of Cards Program I need help printing a flush, which is showing the top 5...

Deck of Cards Program

I need help printing a flush, which is showing the top 5 cards of the same suite.

Below is the code I already have that answers other objectives, such as dealing the cards, and finding pairs.

Towards the end I have attempted printing a flush, but I cannot figure it out.

public class Shuffler {

   /**

   * The number of consecutive shuffle steps to be performed in each call

   * to each sorting procedure.

   */

   private static final int SHUFFLE_COUNT = 1; // Determines amount of times that the numbers will shuffle

   private static final int[] VALUE_COUNT = {0,1,2,3}; // Determines amount of times that the numbers will shuffle

   /**

   * Tests shuffling methods.

   * @param args is not used.

   */

   public static void main(String[] args) {

       System.out.println("Results of " + SHUFFLE_COUNT +

               " consecutive perfect shuffles:");

       int[] values1 = VALUE_COUNT; // This array has the numbers that will be shuffled. The numbers can be changed to anything. This particular array applies to the perfect shuffle.

       for (int j = 1; j <= SHUFFLE_COUNT; j++) { // Prints out the perfect shuffle

           perfectShuffle(values1);

           System.out.print(" " + j + ":");

           for (int k = 0; k < values1.length; k++) {

               System.out.print(" " + values1[k]);

           }

           System.out.println();

       }

       System.out.println();

       System.out.println("Results of " + SHUFFLE_COUNT +

               " consecutive efficient selection shuffles:");

       int[] values2 = VALUE_COUNT;// This array is used for the selection shuffle. The numbers in the array can be changed to anything

       for (int j = 1; j <= SHUFFLE_COUNT; j++) {

           selectionShuffle(values2);

           System.out.print(" " + j + ":");

           for (int k = 0; k < values2.length; k++) { // Prints out the numbers after they are shuffled

               System.out.print(" " + values2[k]);

           }

           System.out.println();

       }

       System.out.println();

   }

   /**

   * Apply a "perfect shuffle" to the argument.

   * The perfect shuffle algorithm splits the deck in half, then interleaves

   * the cards in one half with the cards in the other.

   * @param values is an array of integers simulating cards to be shuffled.

   */

   public static void perfectShuffle(int[] values) { // Intertwines all the cards in the deck by splitting deck in half and mixing the two halves.

       /* *** TO BE IMPLEMENTED IN ACTIVITY 3 *** */

       int [] hold = new int [values.length]; // Creates new array to hold the temporary values that the method will use when it shuffles

       int left = 0; // The left side of the deck will start at the first card

       int right = values.length/2; // Right side will be the entire deck split in half

       for(int i = 0; i<values.length; i+=2){ // Runs the loop how ever many cards there are. It adds two each time.

           hold[i]= values[left]; // replaces the new shuffled value in the hold array

           hold[i+1] = values[right];

           left++; // moves to next card

           right++;

       }

       for(int i = 0; i<values.length; i++){

           values[i] = hold[i]; // replaces all of the ordered cards into the newly shuffled array

       }

   }

   /**

   * Apply an "efficient selection shuffle" to the argument.

   * The selection shuffle algorithm conceptually maintains two sequences

   * of cards: the selected cards (initially empty) and the not-yet-selected

   * cards (initially the entire deck). It repeatedly does the following until

   * all cards have been selected: randomly remove a card from those not yet

   * selected and add it to the selected cards.

   * An efficient version of this algorithm makes use of arrays to avoid

   * searching for an as-yet-unselected card.

   * @param values is an array of integers simulating cards to be shuffled.

   */

   public static void selectionShuffle(int[] values) { // Chooses a random card and puts it at the end of the list. Then takes another card with the remaining ones and puts that next to the previous one.

       /* *** TO BE IMPLEMENTED IN ACTIVITY 3 *** */

       for(int i = values.length-1; i>0; i--){ // Runs through the loop for each of the cards

           int position = (int) (Math.random() * i); // Selects a random card from the pile

           int temp = values[position];

           values[position] = values[i];

           values [i] = temp; // replaces the temporary value with the card that was selected

       }

   }

}

public class Deck{

   /**

   *

   * cards contains all the cards in the deck.

   *

   */

   private List<Card> cards;

   /**

   *

   * size is the number of not-yet-dealt cards.

   *

   * Cards are dealt from the top (highest index) down.

   *

   * The next card to be dealt is at size - 1.

   *

   */

   private int size;

   /**

   *

   * Creates a new <code>Deck</code> instance.<BR>

   *

   * It pairs each element of ranks with each element of suits,

   *

   * and produces one of the corresponding card.

   *

   * @param ranks

   * is an array containing all of the card ranks.

   *

   * @param suits

   * is an array containing all of the card suits.

   *

   * @param values

   * is an array containing all of the card point values.

   *

   */

   public Deck(String[] ranks, String[] suits, int[] values) {

       /* *** TO BE IMPLEMENTED IN ACTIVITY 2 *** */

       cards = new ArrayList<Card>();

       for (int i = 0; i < suits.length; i++) {

           for (int j = 0; j < ranks.length; j++) {

               cards.add(new Card(ranks[j], suits[i], values[j]));

           }

       }

       size = cards.size();

       shuffle();

   }

   /**

   *

   * Determines if this deck is empty (no undealt cards).

   *

   * @return true if this deck is empty, false otherwise.

   *

   */

   public boolean isEmpty() {

       /* *** TO BE IMPLEMENTED IN ACTIVITY 2 *** */

       if (size > 0)

           return false;

       else

           return true;

   }

   /**

   *

   * Accesses the number of undealt cards in this deck.

   *

   * @return the number of undealt cards in this deck.

   *

   */

   public int size() {

       /* *** TO BE IMPLEMENTED IN ACTIVITY 2 *** */

       return size;

   }

   /**

   *

   * Randomly permute the given collection of cards

   *

   * and reset the size to represent the entire deck.

   *

   */

   public void shuffle() {

       /* *** TO BE IMPLEMENTED IN ACTIVITY 4 *** */

       for (int i = cards.size() - 1; i > 0; i--) {

           int t = (int) Math.round(Math.random() * i);

           Card temp = cards.get(i);

           cards.set(i, cards.get(t));

           cards.set(t, temp);

       }

       size = cards.size();

   }

   /**

   *

   * Deals a card from this deck.

   *

   * @return the card just dealt, or null if all the cards have been

   *

   * previously dealt.

   *

   */

   public Card deal() {

       /* *** TO BE IMPLEMENTED IN ACTIVITY 2 *** */

       if (isEmpty())

           return null;

       else {

           size--;

           return cards.get(size);

       } //if the deck is empty a null value is returned and if it is not then the cards are dealt again

   }

   /**

   *

   * Generates and returns a string representation of this deck.

   *

   * @return a string representation of this deck.

   *

   */

   @Override

   public String toString() {

       String rtn = "size = " + size + "\nUndealt cards: \n"; //sets up a string to print out the number of undealt cards

       for (int k = size - 1; k >= 0; k--) {

           rtn = rtn + cards.get(k); //adds the cards to the string to be printed out

           if (k != 0) {

               rtn = rtn + ", ";

           }

           if ((size - k) % 2 == 0) {

               // Insert carriage returns so entire deck is visible on console.

               rtn = rtn + "\n";

           }

       }

       rtn = rtn + "\nDealt cards: \n";

       for (int k = cards.size() - 1; k >= size; k--) {

           rtn = rtn + cards.get(k);

           if (k != size) {

               rtn = rtn + ", ";

           }

           if ((k - cards.size()) % 2 == 0) {

               // Insert carriage returns so entire deck is visible on console.

               rtn = rtn + "\n";

           }

       }

       rtn = rtn + "\n";

       return rtn;

   }

}

public class Card {

/**

   * String value that holds the suit of the card

   */

   private String suit;

   /**

   * String value that holds the rank of the card

   */

   private String rank;

   /**

   * int value that holds the point value.

   */

   private int pointValue;

   /**

   * Creates a new Card instance.

   *

   * @param cardRank

   * a String value containing the rank of the card

   *

   * @param cardSuit

   * a String value containing the suit of the card

   *

   * @param cardPointValue

   * an int value containing the point value of the card

   */

   public Card(String cardRank, String cardSuit, int cardPointValue) {

       /* *** TO BE IMPLEMENTED IN ACTIVITY 1 *** */

       this.rank = cardRank;

       this.suit = cardSuit;

       this.pointValue = cardPointValue;

   }

   /**

   * Accesses this Card's suit.

   *

   * @return this Card's suit.

   */

   public String suit() {

       /* *** TO BE IMPLEMENTED IN ACTIVITY 1 *** */

       return suit;

   }

   /**

   * Accesses this Card's rank.

   *

   * @return this Card's rank.

   */

   public String rank() {

       /* *** TO BE IMPLEMENTED IN ACTIVITY 1 *** */

       return rank;

   }

   /**

   * Accesses this Card's point value.

   *

   * @return this Card's point value.

   */

   public int pointValue() {

       /* *** TO BE IMPLEMENTED IN ACTIVITY 1 *** */

       return pointValue;

   }

   /**

   * Compare this card with the argument.

   *

   * @param otherCard

   * the other card to compare to this

   *

   * @return true if the rank, suit, and point value of this card are equal to

   * those of the argument; false otherwise.

   *

   */

   public boolean matches(Card otherCard) {

       /* *** TO BE IMPLEMENTED IN ACTIVITY 1 *** */

       if (this.pointValue == otherCard.pointValue && this.suit.equals(otherCard.suit)

               && this.rank.equals(otherCard.rank))

           return true;

       else

           return false;

   }

   /**

   * Converts the rank, suit, and point value into a string in the format

   * "[Rank] of [Suit] (point value = [PointValue])". This provides a useful

   * way of printing the contents of a Deck in an easily readable format or

   * performing other similar functions.

   *

   * @return a String containing the rank, suit, and point value of the card.

   */

   @Override

   public String toString() {

       /* *** TO BE IMPLEMENTED IN ACTIVITY 1 *** */

       return rank + " of " + suit + " (point value = " + pointValue + ")";

   }

}

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

import java.lang.reflect.Array;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Collections;

import java.util.Scanner;

public class Hand {

   static ArrayList hand = new ArrayList();

   static String [] ranks = {"Ace", "2", "3","4","5","6","7","8","9","10","Jack","Queen","King"}; // an array with all of the ranks

   static String [] suits = {"spades", "hearts", "clubs", "diamonds"}; // can array with all of the suits

   static int [] values = {1,2,3,4,5,6,7,8,9,10,11,12,13}; // Puts a point value for each of the cards

   public static void main(String args[]) {

       Scanner scan = new Scanner(System.in);

       // Shuffles deck and ask user how many cards

       int cards = 52;

       Deck deck = new Deck(ranks, suits, values); // puts in the format of ranks suits and then values

       deck.shuffle(); // uses the shuffle method to shuffle the deck

       System.out.println("How many cards should be dealt?: ");

       cards = scan.nextInt();

       //takes the users input and put it into a while loop to deal that many cards.

       int index = 0;

       while (index < cards) {

           hand.add(deck.deal()); // deals cards depending on what the user asks for

           index++;

       }

       //Shows the hand.

       System.out.println("");

       System.out.print("Your Hand: \n"); // prints out the hand

       for(int j = 0; j <= hand.size()-1; j++){

           System.out.print("\t"+hand.get(j) + "\n");

       } // prints out the cards in the hand

       for(index = 0; index< hand.size(); index ++)

       {

           String spade;

           spade = hand.get(index).toString();

           if(spade.contains("spades"))

           {

               System.out.println("\tPosition in Hand: " + (index+1) ); // adds one so position in hand doesn't begin with zero

           }

       }

       ArrayList ValueCompare = new ArrayList();

       while (hand.size() > 0) {

           int place = 0; // place of card.

           Card c = (Card)hand.get(0); // Takes the first card and looks at each card after that and sorts it

           for (int j = 1; j < hand.size(); j++) {

               Card c1 = (Card)hand.get(j);

               if ( c1.pointValue() < c.pointValue() ||

                       (c1.pointValue() < c.pointValue() && c1.suit() == c.suit()) ) { // if the point values are different it orders them

                   place = j;

                   c = c1;

               }

           }

           hand.remove(place); // removes the place

           ValueCompare.add(c); // adds the ordered cards to the ValueCompare arraylist

       }

       hand = ValueCompare; // sets hand equal to the ValueCompare

       System.out.println("");

       System.out.print("Ascending Order: \n\t");// prints it out in ascending order

       for(int j = 0; j <= hand.size()-1; j++){

           System.out.print(hand.get(j) + "\n\t");

       }

       Collections.reverse(hand); // reverses it using the collection class

       System.out.println("");

       System.out.print("Descending Order: \n\t");// prints it out in ascending order

       for(int j = 0; j <= hand.size()-1; j++){

           System.out.print(hand.get(j) + "\n\t");

       }

       Collections.reverse(hand); // reverses it using the collection class

       ArrayList RedCards = new ArrayList();

       ArrayList BlackCards = new ArrayList();

       for (int j = 0; j < hand.size(); j++) {

           Card c1 = (Card)hand.get(j);

           if ( c1.suit().equals("hearts") || c1.suit().equals("diamonds")) {

               RedCards.add(c1);

           }

           else{

               BlackCards.add(c1);

           }

       }

       System.out.println("");

       System.out.print("Red Cards: \n\t");

       for(int j = 0; j <= RedCards.size()-1; j++){

           System.out.print(RedCards.get(j) + "\n\t");

       }

       System.out.println("");

       System.out.print("Black Cards: \n\t");

       for(int j = 0; j <= BlackCards.size()-1; j++){

           System.out.print(BlackCards.get(j) + "\n\t");

       }

       System.out.println("");         

       System.out.println("What is the value of the pairs you want?");

       int pairValue =scan.nextInt();

       int numberOfPairs=0;

       for(int i =0; i < hand.size()-1;i++) {

           for(int j = (i+1); j < hand.size()-1; j++ ) {

               if (hand.get(i).pointValue() == hand.get(j).pointValue()) {

                   if (pairValue == hand.get(i).pointValue()){

                       numberOfPairs ++;  

                   }         

               }

           }

       }

       System.out.println("There are " + numberOfPairs + " pair(s) of cards with the value " +pairValue+"." );

  

  

       ArrayList SpadeCards = new ArrayList();

       ArrayList ClubCards = new ArrayList();

       ArrayList HeartCards = new ArrayList();

       ArrayList DiamondCards = new ArrayList();

       int[] SpadeNums = new int[hand.size()];

       for(int i =0;i

           if(hand.get(i).suit().equalsIgnoreCase("spades")){

               SpadeCards.add(hand.get(i));

           }

       }

       if(SpadeCards.size()<5){

          

       }

       else{

           for(int i =0;i

               SpadeNums[i]=SpadeCards.get(i).pointValue();

           }

      

       Arrays.sort(SpadeNums);

       ArrayList SecondSpadeCards = new ArrayList();

       for(int i =0;i

           if(hand.get(i).pointValue()==SpadeNums[4] || hand.get(i).pointValue()==SpadeNums[3]||hand.get(i).pointValue()==SpadeNums[2]||hand.get(i).pointValue()==SpadeNums[1]||hand.get(i).pointValue()==SpadeNums[0]){

               SecondSpadeCards.add(hand.get(i));

           }

           }

               for(int i =0;i

                   System.out.println(SecondSpadeCards.get(i).toString());

           }

      

  

   System.out.println("Your flush is"); // adds one so position in hand doesn't begin with zero

   }

}

}

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

I've made changes to the code to print the first 5 top values. The requirement for the functionality is not clear. But you can hwoever see the code working for flush.

PROGRAM CODE:

Hand.java

package deck;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Collections;

import java.util.Scanner;

public class Hand {

   static ArrayList<Card> hand = new ArrayList<Card>();

   static String [] ranks = {"Ace", "2", "3","4","5","6","7","8","9","10","Jack","Queen","King"}; // an array with all of the ranks

   static String [] suits = {"spades", "hearts", "clubs", "diamonds"}; // can array with all of the suits

   static int [] values = {1,2,3,4,5,6,7,8,9,10,11,12,13}; // Puts a point value for each of the cards

   public static void main(String args[]) {

   Scanner scan = new Scanner(System.in);

   // Shuffles deck and ask user how many cards

   int cards = 52;

   Deck deck = new Deck(ranks, suits, values); // puts in the format of ranks suits and then values

   deck.shuffle(); // uses the shuffle method to shuffle the deck

   System.out.println("How many cards should be dealt?: ");

   cards = scan.nextInt();

   //takes the users input and put it into a while loop to deal that many cards.

   int index = 0;

   while (index < cards) {

   hand.add(deck.deal()); // deals cards depending on what the user asks for

   index++;

   }

   //Shows the hand.

   System.out.println("");

   System.out.print("Your Hand: \n"); // prints out the hand

   for(int j = 0; j <= hand.size()-1; j++){

   System.out.print("\t"+hand.get(j) + "\n");

   } // prints out the cards in the hand

   for(index = 0; index< hand.size(); index ++)

   {

   String spade;

   spade = hand.get(index).toString();

   if(spade.contains("spades"))

   {

   System.out.println("\tPosition in Hand: " + (index+1) ); // adds one so position in hand doesn't begin with zero

   }

   }

   ArrayList<Card> ValueCompare = new ArrayList<Card>();

   while (hand.size() > 0) {

   int place = 0; // place of card.

   Card c = (Card)hand.get(0); // Takes the first card and looks at each card after that and sorts it

   for (int j = 1; j < hand.size(); j++) {

   Card c1 = (Card)hand.get(j);

   if ( c1.pointValue() < c.pointValue() ||

   (c1.pointValue() < c.pointValue() && c1.suit() == c.suit()) ) { // if the point values are different it orders them

   place = j;

   c = c1;

   }

   }

   hand.remove(place); // removes the place

   ValueCompare.add(c); // adds the ordered cards to the ValueCompare arraylist

   }

   hand = ValueCompare; // sets hand equal to the ValueCompare

   System.out.println("");

   System.out.print("Ascending Order: \n\t");// prints it out in ascending order

   for(int j = 0; j <= hand.size()-1; j++){

   System.out.print(hand.get(j) + "\n\t");

   }

   Collections.reverse(hand); // reverses it using the collection class

   System.out.println("");

   System.out.print("Descending Order: \n\t");// prints it out in ascending order

   for(int j = 0; j <= hand.size()-1; j++){

   System.out.print(hand.get(j) + "\n\t");

   }

   Collections.reverse(hand); // reverses it using the collection class

   ArrayList RedCards = new ArrayList();

   ArrayList BlackCards = new ArrayList();

   for (int j = 0; j < hand.size(); j++) {

   Card c1 = (Card)hand.get(j);

   if ( c1.suit().equals("hearts") || c1.suit().equals("diamonds")) {

   RedCards.add(c1);

   }

   else{

   BlackCards.add(c1);

   }

   }

   System.out.println("");

   System.out.print("Red Cards: \n\t");

   for(int j = 0; j <= RedCards.size()-1; j++){

   System.out.print(RedCards.get(j) + "\n\t");

   }

   System.out.println("");

   System.out.print("Black Cards: \n\t");

   for(int j = 0; j <= BlackCards.size()-1; j++){

   System.out.print(BlackCards.get(j) + "\n\t");

   }

   System.out.println("");

   System.out.println("What is the value of the pairs you want?");

   int pairValue =scan.nextInt();

   int numberOfPairs=0;

   for(int i =0; i < hand.size()-1;i++) {

   for(int j = (i+1); j < hand.size()-1; j++ ) {

   if (hand.get(i).pointValue() == hand.get(j).pointValue()) {

   if (pairValue == hand.get(i).pointValue()){

   numberOfPairs ++;

   }

   }

   }

   }

   System.out.println("There are " + numberOfPairs + " pair(s) of cards with the value " +pairValue+"." );

  

  

   ArrayList<Card> SpadeCards = new ArrayList<Card>();

   ArrayList<Card> ClubCards = new ArrayList<Card>();

   ArrayList<Card> HeartCards = new ArrayList<Card>();

   ArrayList<Card> DiamondCards = new ArrayList<Card>();

   Integer[] SpadeNums = new Integer[hand.size()]; //Chaged this from int to Integer

   for(int i =0;i<hand.size(); i++){

   if(hand.get(i).suit().equalsIgnoreCase("spades")){

   SpadeCards.add(hand.get(i));

   }

   }

   if(SpadeCards.size()<5){

  

   }

   else{

   for(int i =0;i<hand.size(); i++){

       if(i<SpadeCards.size()) // Changed code here to insert 0 for the remaining part of the array

           SpadeNums[i]=SpadeCards.get(i).pointValue();

       else SpadeNums[i] = 0;

   }

  

Arrays.sort(SpadeNums, Collections.reverseOrder()); //reverse sorting here so that zeros will go the end and higher values will be in the front.

   ArrayList<Card> SecondSpadeCards = new ArrayList<Card>();

   for(int i =0;i<hand.size(); i++){

   if(hand.get(i).pointValue()==SpadeNums[4] || hand.get(i).pointValue()==SpadeNums[3]||hand.get(i).pointValue()==SpadeNums[2]||hand.get(i).pointValue()==SpadeNums[1]||hand.get(i).pointValue()==SpadeNums[0]){

   SecondSpadeCards.add(hand.get(i));

   }

   }

   for(int i =0;i<SecondSpadeCards.size(); i++){

   System.out.println(SecondSpadeCards.get(i).toString());

   }

  

  

   System.out.println("Your flush is"); // adds one so position in hand doesn't begin with zero

   }

}

}

OUTPUT:

How many cards should be dealt?:

30

Your Hand:

   2 of spades (point value = 2)

   Queen of spades (point value = 12)

   4 of spades (point value = 4)

   5 of hearts (point value = 5)

   7 of spades (point value = 7)

   8 of diamonds (point value = 8)

   8 of spades (point value = 8)

   King of clubs (point value = 13)

   10 of diamonds (point value = 10)

   7 of clubs (point value = 7)

   6 of clubs (point value = 6)

   Ace of diamonds (point value = 1)

   5 of spades (point value = 5)

   6 of spades (point value = 6)

   2 of clubs (point value = 2)

   7 of diamonds (point value = 7)

   10 of spades (point value = 10)

   3 of diamonds (point value = 3)

   9 of diamonds (point value = 9)

   King of diamonds (point value = 13)

   4 of diamonds (point value = 4)

   10 of clubs (point value = 10)

   6 of diamonds (point value = 6)

   Queen of diamonds (point value = 12)

   8 of clubs (point value = 8)

   Jack of hearts (point value = 11)

   Queen of hearts (point value = 12)

   Ace of spades (point value = 1)

   5 of diamonds (point value = 5)

   2 of diamonds (point value = 2)

   Position in Hand: 1

   Position in Hand: 2

   Position in Hand: 3

   Position in Hand: 5

   Position in Hand: 7

   Position in Hand: 13

   Position in Hand: 14

   Position in Hand: 17

   Position in Hand: 28

Ascending Order:

   Ace of diamonds (point value = 1)

   Ace of spades (point value = 1)

   2 of spades (point value = 2)

   2 of clubs (point value = 2)

   2 of diamonds (point value = 2)

   3 of diamonds (point value = 3)

   4 of spades (point value = 4)

   4 of diamonds (point value = 4)

   5 of hearts (point value = 5)

   5 of spades (point value = 5)

   5 of diamonds (point value = 5)

   6 of clubs (point value = 6)

   6 of spades (point value = 6)

   6 of diamonds (point value = 6)

   7 of spades (point value = 7)

   7 of clubs (point value = 7)

   7 of diamonds (point value = 7)

   8 of diamonds (point value = 8)

   8 of spades (point value = 8)

   8 of clubs (point value = 8)

   9 of diamonds (point value = 9)

   10 of diamonds (point value = 10)

   10 of spades (point value = 10)

   10 of clubs (point value = 10)

   Jack of hearts (point value = 11)

   Queen of spades (point value = 12)

   Queen of diamonds (point value = 12)

   Queen of hearts (point value = 12)

   King of clubs (point value = 13)

   King of diamonds (point value = 13)

  

Descending Order:

   King of diamonds (point value = 13)

   King of clubs (point value = 13)

   Queen of hearts (point value = 12)

   Queen of diamonds (point value = 12)

   Queen of spades (point value = 12)

   Jack of hearts (point value = 11)

   10 of clubs (point value = 10)

   10 of spades (point value = 10)

   10 of diamonds (point value = 10)

   9 of diamonds (point value = 9)

   8 of clubs (point value = 8)

   8 of spades (point value = 8)

   8 of diamonds (point value = 8)

   7 of diamonds (point value = 7)

   7 of clubs (point value = 7)

   7 of spades (point value = 7)

   6 of diamonds (point value = 6)

   6 of spades (point value = 6)

   6 of clubs (point value = 6)

   5 of diamonds (point value = 5)

   5 of spades (point value = 5)

   5 of hearts (point value = 5)

   4 of diamonds (point value = 4)

   4 of spades (point value = 4)

   3 of diamonds (point value = 3)

   2 of diamonds (point value = 2)

   2 of clubs (point value = 2)

   2 of spades (point value = 2)

   Ace of spades (point value = 1)

   Ace of diamonds (point value = 1)

  

Red Cards:

   Ace of diamonds (point value = 1)

   2 of diamonds (point value = 2)

   3 of diamonds (point value = 3)

   4 of diamonds (point value = 4)

   5 of hearts (point value = 5)

   5 of diamonds (point value = 5)

   6 of diamonds (point value = 6)

   7 of diamonds (point value = 7)

   8 of diamonds (point value = 8)

   9 of diamonds (point value = 9)

   10 of diamonds (point value = 10)

   Jack of hearts (point value = 11)

   Queen of diamonds (point value = 12)

   Queen of hearts (point value = 12)

   King of diamonds (point value = 13)

  

Black Cards:

   Ace of spades (point value = 1)

   2 of spades (point value = 2)

   2 of clubs (point value = 2)

   4 of spades (point value = 4)

   5 of spades (point value = 5)

   6 of clubs (point value = 6)

   6 of spades (point value = 6)

   7 of spades (point value = 7)

   7 of clubs (point value = 7)

   8 of spades (point value = 8)

   8 of clubs (point value = 8)

   10 of spades (point value = 10)

   10 of clubs (point value = 10)

   Queen of spades (point value = 12)

   King of clubs (point value = 13)

  

What is the value of the pairs you want?

3

There are 0 pair(s) of cards with the value 3.

6 of clubs (point value = 6)

6 of spades (point value = 6)

6 of diamonds (point value = 6)

7 of spades (point value = 7)

7 of clubs (point value = 7)

7 of diamonds (point value = 7)

8 of diamonds (point value = 8)

8 of spades (point value = 8)

8 of clubs (point value = 8)

10 of diamonds (point value = 10)

10 of spades (point value = 10)

10 of clubs (point value = 10)

Queen of spades (point value = 12)

Queen of diamonds (point value = 12)

Queen of hearts (point value = 12)

Your flush is

Add a comment
Know the answer?
Add Answer to:
Deck of Cards Program I need help printing a flush, which is showing the top 5...
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
  • In java---- The DeckTester.java file, provides a basic set of Deck tests. Add additional code at...

    In java---- The DeckTester.java file, provides a basic set of Deck tests. Add additional code at the bottom of the main method to create a standard deck of 52 cards and test the shuffle method ONLY in the Deck class. After testing the shuffle method, use the Deck toString method to “see” the cards after every shuffle. Deck: import java.util.List; import java.util.ArrayList; /** * The Deck class represents a shuffled deck of cards. * It provides several operations including *...

  • NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET...

    NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET CODE TO RUN!! THANKS Extend the DeckofCards and the Card class in the book to implement a card game application such as BlackJack, Texas poker or others. Your game should support multiple players (up to 5 for BlackJack). You must build your game based on the Cards and DeckofCards class from the book. You need to implement the logic of the game. You can...

  • JAVAFX ONLY PROGRAM!!!!! SORTING WITH NESTED CLASSES AND LAMBDA EXPRESSIONS. DIRECTIONS ARE BELOW: DIRECTIONS: The main...

    JAVAFX ONLY PROGRAM!!!!! SORTING WITH NESTED CLASSES AND LAMBDA EXPRESSIONS. DIRECTIONS ARE BELOW: DIRECTIONS: The main point of the exercise is to demonstrate your ability to use various types of nested classes. Of course, sorting is important as well, but you don’t really need to do much more than create the class that does the comparison. In general, I like giving you some latitude in how you design and implement your projects. However, for this assignment, each piece is very...

  • HELP NEED!! Can some modified the program Below in C++ So that it can do what...

    HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...

  • Java Write a complete program that implements the functionality of a deck of cards. In writing...

    Java Write a complete program that implements the functionality of a deck of cards. In writing your program, use the provided DeckDriver and Card classes shown below. Write your own Deck class so that it works in conjunction with the two given classes. Use anonymous objects where appropriate. Deck class details: Use an ArrayList to store Card objects. Deck constructor: The Deck constructor should initialize your ArrayList with the 52 cards found in a standard deck. Each card is a...

  • Given these three classes: Card, DeckOfCards, and DeckOfCardsTest. Extend the DeckofCards class to implement a BlackJack...

    Given these three classes: Card, DeckOfCards, and DeckOfCardsTest. Extend the DeckofCards class to implement a BlackJack class, which implements a BlackJack game. Please do not use any java applet on the coding. Hint: Use a test class to test above classes. Pulic class Card {    private final String face; // face of card ("Ace", "Deuce", ...)    private final String suit; // suit of card ("Hearts", "Diamonds", ...)    // two-argument constructor initializes card's face and suit    public...

  • C Programming The following code creates a deck of cards, shuffles it, and deals to players....

    C Programming The following code creates a deck of cards, shuffles it, and deals to players. This program receives command line input [1-13] for number of players and command line input [1-13] for number of cards. Please modify this code to deal cards in a poker game. Command line input must accept [2-10] players and [5] cards only per player. Please validate input. Then, display the sorted hands, and then display the sorted hands - labeling each hand with its...

  • HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include...

    HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...

  • I am currently using eclipse to write in java. A snapshot of the output would be...

    I am currently using eclipse to write in java. A snapshot of the output would be greatly appreciated to verify that the program is indeed working. Thanks in advance for both your time and effort. Here is the previous exercise code: /////////////////////////////////////////////////////Main /******************************************* * Week 5 lab - exercise 1 and exercise 2: * * ArrayList class with search algorithms * ********************************************/ import java.util.*; /** * Class to test sequential search, sorted search, and binary search algorithms * implemented in...

  • I'm currently writing a program based on stub poker and trying to deal cards to the...

    I'm currently writing a program based on stub poker and trying to deal cards to the players, show their hands, and determine the winner, and lastly ask them to if they want to play another hand. I'm probably going to have to write a method to compare hands but i really need to just deal the cards and store in their hands Any help or suggestions? Here are my current classes. public class PlayingCard {    private final Suit suit;...

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