Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: please advise on which method i can use to compare my out put resault

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default please advise on which method i can use to compare my out put resault

    please i have this task to to but i can only manage to to display five cards but i cant compare my result, here is what should be done:

    (Card Shuffling and Dealing) Modify the application to deal a five-card poker
    hand. Then modify class "DeckOfCards" of to include methods that determine whether a
    hand contains and aslo (Card Shuffling and Dealing) Use the methods developed to write an application
    that deals two five-card poker hands, evaluates each hand and determines which is better.

    a) a pair
    b) two pairs
    c) three of a kind (e.g., three jacks)
    d) four of a kind (e.g., four aces)
    e) a flush (i.e., all five cards of the same suit)
    f) a straight (i.e., five cards of consecutive face values)
    g) a full house (i.e., two cards of one face value and three cards of another face value)

    below is the codes of classes


    < // Card class represents a playing card.
    public class Card 
    {
      private String face; // face of card ("Ace", "Deuce", ...)
       private String suit; // suit of card ("Hearts", "Diamonds", ...)
    // two-argument constructor initializes card's face and suit
     
       public Card( String cardFace, String cardSuit )
       {
          face = cardFace; // initialize face of card
          suit = cardSuit; // initialize suit of card
       } // end two-argument Card constructor
     
       // return String representation of Card
       public String toString() 
       { 
          return face + " of " + suit;
       } // end method toString
    } // end class Card
     
    /***********************************************************************************************************************/
    // Fig. 7.10: DeckOfCards.java
    // DeckOfCards class represents a deck of playing cards.
    import java.util.Random;
     
    public class DeckOfCards
    {
       private Card[] deck; // array of Card objects
       private int currentCard; // index of next Card to be dealt
       private static final int NUMBER_OF_CARDS = 52; // constant # of Cards
       // random number generator
       private static final Random randomNumbers = new Random();
     
       // constructor fills deck of Cards
       public DeckOfCards()
       {
          String[] faces = { "Ace", "Deuce", "Three", "Four", "Five", "Six",
             "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
          String[] suits = { "Hearts", "Diamonds", "Clubs", "Spades" };
     
          deck = new Card[ NUMBER_OF_CARDS ]; // create array of Card objects
          currentCard = 0; // set currentCard so first Card dealt is deck[ 0 ]
     
          // populate deck with Card objects
          for ( int count = 0; count < deck.length; count++ )
             deck[ count ] =
                new Card( faces[ count % 13 ], suits[ count / 13 ] );
       } // end DeckOfCards constructor
     
       // shuffle deck of Cards with one-pass algorithm
       public void shuffle()
       {
          // after shuffling, dealing should start at deck[ 0 ] again
          currentCard = 0; // reinitialize currentCard
     
          // for each Card, pick another random Card and swap them
          for ( int first = 0; first < deck.length; first++ )
          {
             // select a random number between 0 and 51
             int second =  randomNumbers.nextInt( NUMBER_OF_CARDS );
     
             // swap current Card with randomly selected Card
             Card temp = deck[ first ];
             deck[ first ] = deck[ second ];
             deck[ second ] = temp;
          } // end for
       } // end method shuffle
     
     
       // deal one Card
       public Card dealCard()
       {
          // determine whether Cards remain to be dealt
          if ( currentCard < deck.length )
             return deck[ currentCard++ ]; // return current Card in array
          else
             return null; // return null to indicate that all Cards were dealt
       } // end method dealCard
     
     
    } // end class DeckOfCards
     
     
    /********************************************************************************************************/
     // Fig. 7.11: DeckOfCardsTest.java
    // Card shuffling and dealing.
     
    public class DeckOfCardsTest
    {
       // execute application
       public static void main( String[] args )
       {
          DeckOfCards myDeckOfCards = new DeckOfCards();
          myDeckOfCards.shuffle(); // place Cards in random order
     
          // print all 52 Cards in the order in which they are dealt
          for ( int i = 1; i <= 5; i++ )
          {
             // deal and display a Card
             System.out.printf( "%-19s", myDeckOfCards.dealCard() );
     
    		 if ( i % 1 == 0 ) // output newline every 4 cards
    		    System.out.println();
          } // end for
       } // end main
    } // end class DeckOfCardsTest
     
     
    /**************************************************************************
     
    /***********the output are as follows****/
    so if one can be able to show me the method to find only question a,then i can at least try to find the rest
     
    Ace of Spades      
    Five of Hearts     
    Six of Diamonds    
    Nine of Hearts     
    Three of Diamonds  
     
    Process completed.>


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: please advise on which method i can use to compare my out put resault

    cant compare my result,
    One way would be a method that takes two hands and returns a value indicating which hand is better than the other hand.

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please advise on which method i can use to compare my out put resault

    Norm i have made some changes but i don't know if that is was what you have been looking for

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: please advise on which method i can use to compare my out put resault

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please advise on which method i can use to compare my out put resault

    Norm i hope this is what you were asking for

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: please advise on which method i can use to compare my out put resault

    The posted code's formatting is much better now.

    What is the status of the project now?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please advise on which method i can use to compare my out put resault

    like how i dont understand, but i just need help to solution for quetion a, and b, and the rest i can at-least try

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: please advise on which method i can use to compare my out put resault

    What is question a? Are you talking about this:
    a) a pair
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Apr 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please advise on which method i can use to compare my out put resault

    ok i have the code but this code it doesn't indicate whether the cards its a straight,four of a kind, full house, two pairs or one pair. for example when i deal the cards and lets say the random number generates "Ace of spade","Ace of Hearts","Ace of love","Ace of Duece" and any ather kind of card then the3program should output those random numbers as it does so far then also tell that this is "four of a kind"

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: please advise on which method i can use to compare my out put resault

    Do you have a question?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. where to put list of objects method OOP
    By stanlj in forum Object Oriented Programming
    Replies: 3
    Last Post: January 14th, 2013, 01:08 PM
  2. Replies: 7
    Last Post: November 6th, 2011, 06:15 PM
  3. Replies: 1
    Last Post: November 5th, 2011, 10:56 AM
  4. Need Advise!!!
    By Mr.777 in forum Member Introductions
    Replies: 1
    Last Post: May 16th, 2011, 09:36 AM
  5. Compare method
    By Evelina in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 16th, 2010, 02:07 PM