Question: In JAVA - ADT Lists In-Between is a well-known card game. Many variations existwe define it as follows. One deck of cards is used. A

In JAVA - ADT Lists

In-Between is a well-known card game. Many variations existwe define it as follows. One deck of cards is used. A game consists of one or more hands. A player starts with a certain number of chips called the stake (say 100) and must risk one or more chips on each hand, before seeing any cards. As long as the player still has chips and there are three or more cards left in the deck (enough to play a hand), the game continues. For each hand the player must risk between one and their total number of chips. Two cards are dealt face up. Then a third card is dealt. If the third card is in-between the first two cards, based on the ranks of the cards, the players chips are increased by the amount risked. Otherwise they are decreased by that amount.

1 Implement the game. The application user is the player.

2 If the first two cards dealt are the same rank, that hand is over and the player is awarded two chips.

3 Allow the player at his or her discretion to double the risk after seeing the first two cards.

4 Implement a graphical user interfacebased version of the In-Between game .

//----------------------------------------------------------------------

// CardDeck.java by Dale/Joyce/Weems Chapter 6

//

// Models a deck of cards. Includes shuffling and dealing.

//----------------------------------------------------------------------

//package support.cards;

import java.util.Random;

//import java.util.Card;

//import ch06.lists.ABList;

import javax.swing.ImageIcon;

public class CardDeck

{

public static final int NUMCARDS = 52;

protected ABList deck;

protected Iterator deal;

public CardDeck()

{

deck = new ABList(NUMCARDS);

ImageIcon image;

for (Card.Suit suit : Card.Suit.values())

for (Card.Rank rank : Card.Rank.values())

{

image = new ImageIcon("support/cards/" + suit + "_" + rank

+ "_RA.gif");

deck.add(new Card(rank, suit, image));

}

deal = deck.iterator();

}

public void shuffle()

// Randomizes the order of the cards in the deck.

// Resets the current deal.

{

Random rand = new Random(); // to generate random numbers

int randLoc; // random location in card deck

Card temp; // for swap of cards

for (int i = (NUMCARDS - 1); i > 0; i--)

{

randLoc = rand.nextInt(i); // random integer between 0 and i - 1

temp = deck.get(randLoc);

deck.set(randLoc, deck.get(i));

deck.set(i, temp);

}

deal = deck.iterator();

}

public boolean hasNextCard()

// Returns true if there are still cards left to be dealt;

// otherwise, returns false.

{

return (deal.hasNext());

}

public Card nextCard()

// Precondition: this.hasNextCard() == true

//

// Returns the next card for the current 'deal'.

{

return deal.next();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!