Hello my name is Leonard Norwood Jr.
I'm doing a little Poker thing right now on my own time for practice, but I have a heck of a problem. I'm making two classes called Poker.java and PlayPokerDriver.java right now, and I'm almost finished by somewhere between initializing the decks I made a public void actionPerformed (which I called for now) that is lacking something. I don't know what but I do know that the indentation is mostly fixed up, but I only have 4 errors left. So I'm almost done compiling this thing. Another problem is PlayPokerDriver is even worse with 32 errors, and I think I know better than to type whatever I just typed, knowing I didn't truly need to put it in there. All in All, I need help with trying fix these things so they can work. I was still working out the constructors in Poker.java, so I thought I would leave what I got like that until I could slowly learn what I did wrong and fix it. But it's taking me some time and leaving it undone is a habit I'd rather not display at all in any points in my life. Any help is appreciated. I'll check in as soon as possible.
Poker.java
public class Poker
{
//public static final int NCARDS = 52;
private Card[] deckOfCards; // Contains 52 cards values, from 0 to 51 or 1 to 51.
private Card[] hand; // Contain 5 cards in a hand.
private int currentCard; //
private int numbers[], triples, couples; // numbers of a triples or couples, that
private String faces[], suits[], output; //
/* ---------------------------------------------
The constructor method: make 52 cards in deck
---------------------------------------------*/
public Poker()
{
String faceArray[] = { "Ace", "Deuce", "Three", "Four",
"Five", "Six", "Seven", "Eight", "Nine", "Ten",
"Jack", "Queen", "King" };
String suitArray[] = { "Hearts", "Diamonds", "Clubs", "Spades" };
faces = faceArray;
suits = suitArray;
numbers = new int [ 13 ];
triples = 0;
couples = 0;
deckOfCards = new Card [ 52 ];
hand = new Card [ 5 ];
currentCard = -1;
//initilize the deck array
for ( int count = 0; count < deckOfCards.length; count++ )
{
deckOfCards [ count ] = new Card (faces[ count % 13 ],
suits [ count / 13] );
}
public void actionPerformed( ActionEvent e)
{
output = "";
triples = 0;
couples = 0;
// deal a round of cards
for (int count = 0; count < hand.length; count++)
{
Card dealt = dealCard();
if(dealt != null)
{
hand[ count ] = dealt;
system.out.println (hand [ count ].toString() + "\n");
}
else
{
system.out.println("NOT ENOUGH CARDS TO DEAL");
return;
}
}
//calculate contents of the hand
totalHand();
pairs();
twoPair();
threeOfAKind();
FourOfAKind();
flush();
}
}// end Class Poker
// shuffle deck
public void shuffle()
{
int d = deckOfCards.length;
for (int i = 0; i < d; i++)
{
int r = i + (int) (Math.random() * (d-i));
String temp = deckOfCards[r];
deckOfCards[r] = deckOfCards[i];
deckOfCards[i] = temp;
currentCard = -1;
}
}// ends shuffle()
//repeat for N number of people to deal
public void dealCard()
{
//for (int t = 0; t <players.length ; t++)
//{
if (++currentCard < deck.length)
return deck[ currentCard ];
else
{
System.out.print("Out of cards error. ");
return (null); // Error
// print 5 random cards
//*for (int i = 0; i < 5; i++)
// System.out.print(deckOfCards[i] + " ");
// System.out.println();*/
//}
}
}
private void totalHand()
{
// initialize all elements of numbers[] to zero
for ( int x = 0; x < faces.length; x++ )
numbers[ x ] = 0;
// compare each card in the hand to each element in the faces array
for ( int h = 0; h < hand.length; h++ )
for ( int f = 0; f < faces.length; f++ )
if ( hand[ h ].getFace().equals( faces[ f ] ) )
++numbers[ f ];
}
// determine if hand contains pairs
public void pairs()
{
for ( int k = 0; k < faces.length; k++ )
if ( numbers[ k ] == 2 )
{
output += ( "Pair of " + faces[ k ] + "'s " );
couples++;
}
system.out.println( output );
}
// determine if hand contains a three of a kind
public void threeOfAKind()
{
for ( int k = 0; k < faces.length; k++ )
if ( numbers[ k ] == 3 )
{
output += ( "Three " + faces[ k ] + "'s" );
triples++;
break;
}
system.out.println( output );
}
// determine if hand contains a four of a kind
public void fourOfAKind()
{
for ( int k = 0; k < faces.length; k++ )
if ( numbers[ k ] == 4 )
output += ( "Four " + faces[ k ] + "'s" );
system.out.println( output );
}
// determine if hand contains a flush
public void flush()
{
String theSuit = hand[ 0 ].getSuit();
for ( int s = 1; s < hand.length; s++ )
if ( hand[ s ].getSuit().compareTo( theSuit ) != 0 )
return; // not a flush
output += ( "Flush in " + theSuit );
system.out.println( output );
}
// determine if hand contains a straight
public void straight()
{
int locations[] = new int[ 5 ], z = 0;
for ( int y = 0; y < numbers.length; y++ )
if ( numbers[ y ] == 1 )
locations[ z++ ] = y;
bubbleSort( locations );
int faceValue = locations[ 0 ];
for ( int m = 1; m < locations.length; m++ )
{
if ( faceValue != locations[ m ] - 1 )
return; // not a straight
else
faceValue = locations[ m ];
}
output += "Straight ";
system.out.print( output );
}
// sort hand in ascending order
private void bubbleSort( int values[] )
{
for ( int pass = 1; pass < values.length; pass++ )
for ( int comp = 0; comp < values.length - 1; comp++ )
if ( values[ comp ] > values[ comp + 1 ] ) {
int temp = values[ comp ];
values[ comp ] = values[ comp + 1 ];
values[ comp + 1 ] = values[ comp ];
}
}
// determine if hand contains a full house
public void fullHouse()
{
if ( couples == 1 && triples == 1 ) {
output += "\nFull House!";
system.out.println( output );
}
}
// determine if hand contains two pairs
public void twoPair()
{
if ( couples == 2 ) {
output += "\nTwo Pair!";
system.out.println( output );
}
}
// internal class to represent card
class Card
{
private String face;
private String suit;
// constructor to initialize Card
public Card( String f, String s )
{
face = f;
suit = s;
}
// get suit
protected String getSuit()
{
return suit;
}
// get face
protected String getFace()
{
return face;
}
// return String representation of Card
public String toString()
{
return face + " of " + suit;
}// end Card
}// end clsss Card
}// end class Poker
PlayPokerDriver.java
public class PlayPokerDriver
{
public static void main(String[] args)
{
Poker a;
Card[] player1 = new Card [ 5 ];
Card[] player2 = new Card [ 5 ];
Card[] player3 = new Card [ 5 ];
Card[] player4 = new Card [ 5 ];
int i;
a = new DealPokerCardsNorwood2();
System.out.println(a);
a.Poker();
a.shuffle(1000);
System.out.println("Shuffle cards....");
System.out.println(a);
for (i = 0; i < 5; i++)
{
player1[i] = a.dealCard();
player2[i] = a.dealCard();
player3[i] = a.dealCard();
player4[i] = a.dealCard();
}
System.out.print("Player 1's hand: ");
for (i = 0; i < 5; i++)
System.out.print( player1[i] + " ");
System.out.print( output );
System.out.print("Player 2's hand: ");
for ( i = 0; i < 5; i++)
System.out.print( player2[i] + " ");
System.out.print( output );
System.out.print("Player 3's hand: ");
for ( i = 0; i < 5; i++)
System.out.print( player3[i] + " ");
System.out.print( output );
System.out.print("Player 4's hand: ");
for ( i = 0; i < 5; i++)
System.out.print( player4[i] + " ");
System.out.print( output );
if (a.Poker(player1) > a.Poker(player2) > a.Poker(player3) > a.Poker(player4)) || (a.Poker(player1) > a.Poker(player2) < a.Poker(player3) < a.Poker(player4)) ||
(a.Poker(player1) > a.Poker(player2) < a.Poker(player3)> a.Poker(player4))
System.out.println("Player 1 wins");
else if(a.Poker(player1) < a.Poker(player2) > a.Poker(player3) > a.Poker(player4)) || (a.Poker(player1) < a.Poker(player2) > a.Poker(player3) < a.Poker(player4))
System.out.println("Player 2 wins");
else if(a.Poker(player1) < a.Poker(player2) < a.Poker(player3) > a.Poker(player4)) || (a.Poker(player1) > a.Poker(player2) < a.Poker(player3) > a.Poker(player4))
System.out.println("Player3 wins");
else if(a.Poker(player1) < a.Poker(player2) < a.Poker(player3) < a.Poker(player4)) || (a.Poker(player1) > a.Poker(player2) > a.Poker(player3) < a.Poker(player4)) ||
(a.Poker(player1) < a.Poker(player2) > a.Poker(player3) < a.Poker(player4))
System.out.print("Player 4 wins");
else
System.out.print("All players are tied");
}
}