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 2 of 2

Thread: I keep getting errors within my code and i dont know why

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

    Unhappy I keep getting errors within my code and i dont know why

    I have tried so much to solve this code, from line commenting crap out to deleting stuff. I follow the quick fix in eclipse but it never solved anything. It just creates a bunch of more errors. I have this due may 9. Im scared im going to fail this final. Please help.


    This is for a five card stud game and this is my final.
    Instructions:
    Write a game of 5 card stud, where you play against the computer. The computer will be the dealer.

    The computer will always be the dealer, and will always match all bets by the player. The dealer will start out with 5 times as much money as the player
    (Remember, the house always wins, so they can afford it)
    The player will put money on the table to enter the game (an initial bet), called the ante.
    Both players are dealt 1 card face down, then one card face up.
    Loop until each player has 5 cards – each round gives both players 1 card
    Each player can bet, check (a bet of 0), or fold (give up this game)
    Once all bets have been made, another card is dealt face up to all players
    Once all players have 5 cards, a final bet is made, or the player can fold
    All players show all cards
    The player with the best hand wins the pot
    The dealer collects all cards and shuffles the deck, and another hand is played until the player chooses to quit or one of the two players is out of money.
    If a player folds, the dealer wins the pot automatically. For simplicity, our dealer (the computer) will never fold, and will match all bets from the player.

    THIS IS MY FiveCardStud CLASS
    package application;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    import Card;

    public class FiveCardStud extends JFrame
    {
    static final long serialVersionUID = 3961121256483997973L;

    private Card deck[];
    private int currentCard;
    private JButton dealButton, shuffleButton, testButtton;
    private JTextField displayField;
    private JLabel statusLabel;
    private JLabel cardback, card1, card2,card3,card4,card5,card6,card7,card8,card9,ca rd10;
    private JTextField hand1TF, hand2TF;

    Card dealt;
    Icon card = new ImageIcon(".\\cards\\back2.GIF");
    Card hand1[];
    Card hand2[];
    int handNums[];
    int test;


    public void poker2()
    {
    super( "5-Card Stud" );
    String faces[] = { "Ace", "Deuce", "Three", "Four", "Five", "Six",
    "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };

    String suits[] = { "Hearts", "Diamonds", "Clubs", "Spades" };

    deck = new Card[ 52 ];
    hand1 = new Card[5];
    hand2 = new Card[5];
    handNums = new int[13];
    currentCard = -1;
    test = 4;

    for ( int count = 0; count < deck.length; count++ )
    deck[ count ] = new Card( faces[ count % 13 ],suits[ count / 13 ] );

    Container container = getContentPane();
    container.setLayout( new FlowLayout() );

    card1 = new JLabel();
    card1.setIcon(card);
    container.add( card1 );
    card3 = new JLabel();
    card3.setIcon(card);
    container.add( card3 );
    card5 = new JLabel();
    card5.setIcon(card);
    container.add( card5 );
    card7 = new JLabel();
    card7.setIcon(card);
    container.add( card7 );
    card9 = new JLabel();
    card9.setIcon(card);
    container.add( card9 );
    hand1TF = new JTextField(32);
    hand1TF.setEditable( false );
    hand1TF.setText( "Here it Is" );
    container.add( hand1TF );
    card2 = new JLabel();
    card2.setIcon(card);
    container.add( card2 );
    card4 = new JLabel();
    card4.setIcon(card);
    container.add( card4 );
    card6 = new JLabel();
    card6.setIcon(card);
    container.add( card6 );
    card8 = new JLabel();
    card8.setIcon(card);
    container.add( card8 );
    card10 = new JLabel();
    card10.setIcon(card);
    container.add( card10 );
    hand2TF = new JTextField(32);
    hand2TF.setEditable( false );
    hand2TF.setText( "Here Theirs Are" );
    container.add( hand2TF );

    dealButton = new JButton( "DEAL 'EM" );

    dealButton.addActionListener(
    new ActionListener()
    {

    public void actionPerformed( ActionEvent actionEvent )

    {
    dealt = dealCard();
    if ( dealt != null )
    {
    displayField.setText( dealt.viewcard() );
    showcard(currentCard);
    statusLabel.setText( "Card #: " + (currentCard + 1) );
    }

    else
    {
    displayField.setText( "NO MORE CARDS TO DEAL" );
    statusLabel.setText( "Shuffle cards to continue" );
    }

    int i;
    i = 0;

    if(currentCard % 2 == 0)
    {
    hand2 = dealt;
    i++;
    }

    else
    {
    hand1[currentCard / 2] = dealt;
    }

    }
    }
    );
    container.add( dealButton );
    dealButton.setEnabled(false);

    shuffleButton = new JButton( "Shuffle cards" );
    shuffleButton.addActionListener(
    new ActionListener()
    {
    public void actionPerformed( ActionEvent actionEvent )
    {
    displayField.setText( "SHUFFLING ..." );
    shuffle();
    displayField.setText( "DECK IS SHUFFLED" );

    card = new ImageIcon(".\\cards\\back2.GIF");
    card1.setIcon(card);
    card2.setIcon(card);
    card3.setIcon(card);
    card4.setIcon(card);
    card5.setIcon(card);
    card6.setIcon(card);
    card7.setIcon(card);
    card8.setIcon(card);
    card9.setIcon(card);
    card10.setIcon(card);
    dealButton.setEnabled(true);
    }
    private void evalHand()
    {
    int i;
    for(i = 0; i < hand1.length;i++)
    {
    if(hand1.face.equals("Ace"))
    {
    handNums[0]++;
    }

    }

    container.add( shuffleButton );
    displayField = new JTextField( 20 );
    displayField.setEditable( false );
    container.add( displayField );
    statusLabel = new JLabel();
    container.add( statusLabel );
    setSize( 400, 400 );
    setResizable(false);
    }
    private void shuffle()
    {
    currentCard = -1;
    for ( int first = 0; first < deck.length; first++ ) {
    int second = ( int ) ( Math.random() * 52 );
    Card temp = deck[ first ];
    deck[ first ] = deck[ second ];
    deck[ second ] = temp;
    }

    }

    private Card dealCard()
    {
    if ( ++currentCard < deck.length )
    return deck[ currentCard ];
    else {
    dealButton.setEnabled( false );
    return null;
    }
    }
    private void showcard(int c)
    {

    card = new ImageIcon(getCard(dealt));
    switch (c)
    {
    case 0: card1.setIcon(card); break;
    case 1: card2.setIcon(card); break;
    case 2: card3.setIcon(card); break;
    case 3: card4.setIcon(card); break;
    case 4: card5.setIcon(card); break;
    case 5: card6.setIcon(card); break;
    case 6: card7.setIcon(card); break;
    case 7: card8.setIcon(card); break;
    case 8: card9.setIcon(card); break;
    case 9: card10.setIcon(card);
    dealButton.setEnabled(false);
    break;
    }
    }

    private String getCard(Card myCard)
    {
    String str_return = ".\\cards\\";

    if (myCard.suit.equals("Hearts")) str_return += "H";
    if (myCard.suit.equals("Diamonds")) str_return += "D";
    if (myCard.suit.equals("Clubs")) str_return += "C";
    if (myCard.suit.equals("Spades")) str_return += "S";

    if (myCard.face.equals("Ace")) str_return += "14";
    if (myCard.face.equals("Deuce")) str_return += "2";
    if (myCard.face.equals("Three")) str_return += "3";
    if (myCard.face.equals("Four")) str_return += "4";
    if (myCard.face.equals("Five")) str_return += "5";
    if (myCard.face.equals("Six")) str_return += "6";
    if (myCard.face.equals("Seven")) str_return += "7";
    if (myCard.face.equals("Eight")) str_return += "8";
    if (myCard.face.equals("Nine")) str_return += "9";
    if (myCard.face.equals("Ten")) str_return += "10";
    if (myCard.face.equals("Jack")) str_return += "11";
    if (myCard.face.equals("Queen")) str_return += "12";
    if (myCard.face.equals("King")) str_return += "13";
    return (str_return += ".gif");
    }
    public static void main (String[] args)
    {

    poker application = new poker();
    application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE )
    }

    THIS IS MY Card CLASS
    package application;
    public class Card {
    public String face;
    public String suit;

    public Card( String cardFace, String cardSuit )
    {
    face = cardFace;
    suit = cardSuit;
    }

    public String viewcard()
    {
    return face + " of " + suit;
    }
    }

  2. #2
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: I keep getting errors within my code and i dont know why

    Please edit your post and place the formatted code between code tags (See BBCodes below for more info). You can do this by going to the advanced editor, highlighting your code and clicking the # menu item.

    And please explain what problems you are having.

    Regards,
    Jim

Similar Threads

  1. I dont know what to do with this code
    By rbp1973rbp in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 9th, 2019, 06:17 AM
  2. I have recieved 5 errors... I dont know what they mean...
    By squirrelmind in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 21st, 2014, 03:39 PM
  3. I dont understand this code ?
    By ammehmeti in forum What's Wrong With My Code?
    Replies: 12
    Last Post: June 22nd, 2014, 07:57 AM
  4. Replies: 7
    Last Post: May 8th, 2014, 12:51 PM
  5. a HUGE list of errors, and i dont know why.
    By MR bruto in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 10th, 2013, 07:10 AM

Tags for this Thread