Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Programming The poker game application was designed and developed in Chapte

ID: 3812900 • Letter: J

Question

Java Programming

The poker game application was designed and developed in Chapter 11 of book Java from ground up. The game consists of seven interacting classes: Player, PokerGame, Bet, Deck, Card, Hand, and Bankroll. The details of these classes are summarized as follows.

Bankroll bankroll

PokerGame pg

Initialize the bankroll.

Add coins.
Bet and Play.

Discard.

Display a Hand.

Quit.
Display final results.

PokerGame

Player player

Bet bet

Bankroll bankroll

Hand hand

View initial hand.

Discard or hold cards.
Update bankroll

int bet

Get the bet.

Set the bet.

Deck

Card deck[]

Shuffle the deck.

Deal a card.

Card

int suit

int value

Get the suit.

Get the value, i.e., rank.

Get the name of a card.

Hand

Card [] hand
Deck deck

Evaluate the hand.
Deal a new hand.

Update a hand.
Give the hand.

Bankroll

int bankroll

Get the bankroll.

Set the bankroll.

Change the bankroll.

These classes are implemented in Chapter 11, where the Player class provides a text-based user interface. In Chapter 20, the Player class is reimplemented , replacing text-based input and output with a GUI of buttons, labels, and pictures.

Requirements

Carefully read Chapter 11 and Chapter 20 to understand the class design and implementation of all seven classes for the video poker game.

Implement all classes. You can copy the implementation from the textbook, but you have to debug the program if any errors exist.

Add a menu to the GUI-based Player class. Your menu should include the following menu items: Check the coin balance, Add coins to the bankroll, Start a new game, Exit the game.

You may add some other features, for example, save the coin balance to a file so that the balance can be loaded when you re-run your program. This is optional.

Test the complete implementation.

Submission

The completed project should be included in a single file and submitted onto the blackboard. The hardcopy or email submission will not be accepted. Your submission should include:

The class diagram.

The Java code for all classes, all put in a single word or PDF file.

You have to demonstrate your program execution to the instructor. The demonstration time will be arranged during class meeting and/or the instructor office hours.

Class Attributes Actions Player

Bankroll bankroll

PokerGame pg

Bet bet

Initialize the bankroll.

Add coins.
Bet and Play.

Discard.

Display a Hand.

Quit.
Display final results.

Present a menu.

PokerGame

Player player

Bet bet

Bankroll bankroll

Hand hand

View initial hand.

Discard or hold cards.
Update bankroll

Bet

int bet

Get the bet.

Set the bet.

Deck

Card deck[]

Shuffle the deck.

Deal a card.

Card

int suit

int value

Get the suit.

Get the value, i.e., rank.

Get the name of a card.

Hand

Card [] hand
Deck deck

Evaluate the hand.
Deal a new hand.

Update a hand.
Give the hand.

Bankroll

int bankroll

Get the bankroll.

Set the bankroll.

Change the bankroll.

Explanation / Answer

//Laying out the frame

public class Player extends JFrame

{

private JLabel resultLabel; // label displays the type of hand and the payout

private JLabel[] cardLabel; // an array of 5 labels that display card images

private JButton[] holdButton; // click to keep a particular card

private JButton add1Button; // add 1 coin

private JButton add5Button // clicking adds 5 coins;

private JLabel bankrollLabel; // label that displays the current number of coins

private JButton quitButton; // exit the application

private JButton dealButton; // click to display the updated hand

private JButton[] betAndPlayButton; // clicking any of these buttons makes a bet and begins play

public Player() // default constructor, places all components

{

super("Video Poker");

setBounds(0,0,400,500);

.          // the label at the top of the frame

resultLabel = new JLabel();

resultLabel.setFont(new Font("Arial", Font.BOLD, 18));

resultLabel.setText("Video poker");

//The five card images , the initial image is "Back.gif," which is a dummy card

cardLabel = new JLabel[5];

for (int i = 0; i < 5; i++)

cardLabel[i] = new JLabel(new ImageIcon("Back.gif"));

// the five hold/discard buttons

holdButton = new JButton[5];

for (int i = 0; i <5; i++)

{

holdButton[i] = new JButton(""+(i+1)); // initially these have numbers

holdButton[i].setFont(new Font("Arial",Font.BOLD, 18));

holdButton[i].setEnabled(false); // initially turned off

}

// the five bet and play buttons

betAndPlayButton = new JButton[5];

for ( int i = 0; i < 5; i++)

{

betAndPlayButton[i] = new JButton("Bet "+(i+1));

betAndPlayButton[i].setEnabled(false); // initially turned off

betAndPlayButton[i].setFont(new Font("Arial", Font.BOLD, 15));

}

// the deal button, initially turned off

dealButton = (new JButton("Deal"));

dealButton.setFont(new Font("Arial", Font.BOLD, 18));

dealButton.setEnabled(false);

// the quit button

quitButton = new JButton("Quit");

quitButton.setFont(new Font("Arial", Font.BOLD, 15));

// label that displays current number of coins, the bankroll

bankrollLabel = new JLabel();

bankrollLabel.setFont(new Font("Arial", Font.BOLD, 24));

bankrollLabel.setText("Coins remaining: " + 0 ); // initially no coins

// two buttons that add 1 0r 5 coins to the machine

add1Button = new JButton("Add 1");

add5Button = new JButton("Add 5");

add1Button.setFont(new Font("Arial", Font.BOLD, 15));

add5Button.setFont(new Font("Arial", Font.BOLD, 15));

// panel for the play buttons, card labels, hold buttons, deposit buttons, deal and quit

          JPanel centerPanel = new JPanel(new GridLayout(4,5));

          // add the five bet-and -play buttons

          for (int i = 0; i < 5; i++)

               centerPanel.add(betAndPlayButton[i]);

          //add the five labels that displays the card images

          for (int i = 0; i < 5; i++)

               centerPanel.add(cardLabel[i]);

          // add the five hold buttons

          for (int i = 0; i < 5; i++)

               centerPanel.add(holdButton[i]);

// add the two deposit buttons, the a blank button, the deal and quit buttons

          centerPanel.add(add1Button);

          centerPanel.add(add5Button);

          centerPanel.add(new JButton()); // a blank button as a separator

          centerPanel.add(dealButton);

          centerPanel.add(quitButton);

          //add the label that displays the results to the NORTH section of the frame

          add(resultLabel, BorderLayout.NORTH);

          // add the label that displays the coin count to the SOUTH section of the frame

          add(bankrollLabel, BorderLayout.SOUTH);

          // add the panel with the buttons and card labels to the CENTER of the frame

          add(centerPanel, BorderLayout.CENTER);

          setResizable(false);

          setVisible(true);

     }

}

//To add coins

public class Player extends JFrame

{

private JLabel resultLabel;     // label displays the type of hand and the payout

private JLabel[] cardLabel;        // an array of 5 labels that display card images

private JButton[] holdButton; // click to keep a particular card

private JButton add1Button;    // clicking adds 1 coin

private JButton add5Button; // clicking adds 5 coins

private JLabel bankrollLabel;    // label that displays the current number of coins

private JButton quitButton; // exit the application

private JButton dealButton; // click to display the updated hand

private JButton[] betAndPlayButton; // clicking buttons makes a bet and
//begins play

private Bankroll bankroll; // manages the number of coins in the machine

public Player()      // constructor, places all components, registers listeners

{

bankroll = newBankroll();

add1Button.addActionListener(new ButtonListener()); //register listener

add5Button.addActionListenet( new Button Listener()); // register listener

}

private class ButtonListener implements ActionListener// responds to button events

{

public void actionPerformed( ActionEvent e)

{

if ((e.getSource() == add1Button) ||
(e.getSource() == add5Button))

. {

if (e.getSource() == add1Button)

bankroll.alterBankroll(1);   // add one coin to the bankroll

else

bankroll.alterBankroll(5); // add 5 coins

int br = bankroll.getBankroll(); // total number of coins deposited

bankrollLabel. setText("Coins remaining: "+ br ); // display total coins

// enable the appropriate bet buttons

for ( int i = 0; i < 5; i++)     

if (br >= (i+1))

betAndPlayButton[i].setEnabled(true);

return;

.               }

.          }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote