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

In­ Between is a well­ known card game. Many variations exist—we define it as fo

ID: 3811075 • Letter: I

Question

In­ Between is a well­ known card game. Many variations
exist—we 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 player’s chips are increased by the amount risked.
Otherwise they are decreased by that amount.

java


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.

Explanation / Answer

public class PlayingCard implements Comparable{
// class variables
PlayingSuit _suit;
String val;
int _cardRank;
String _cardColor;
   // constructor
public PlayingCard(){
this(PlayingSuit.JOKER,"Joker",1);
}
public PlayingCard(PlayingSuit _suit, String val, int _cardRank){
this._suit = _suit;
this.val = val;
this._cardRank = _cardRank;

if(_suit == PlayingSuit._DIAMONDS || _suit == PlayingSuit._HEARTS)
_cardColor = "Red";
else
_cardColor = "Black";
}

// getter setters methods
public PlayingSuit getSuitVal() {
return _suit;
}

public String getColorVal() {
return _cardColor;
}

public String getVal() {
return val;
}

public int getRankVal() {
return _cardRank;
}

   // tostring
public String toString(){
return this.val + " -> " + this._suit;
}
   // comparing _playingCards
public int compareTo(Object cardObj){

if(!(cardObj instanceof PlayingCard))
return 0;

PlayingCard other = (PlayingCard)cardObj;

if(this._cardRank < other._cardRank)
return 1;
if(this._cardRank == other._cardRank)
return 0;
if(this._cardRank > other._cardRank)
return -1;

return 0;
}
}

-----------------------------------------------------------------------------------------------------------------------
import java.util.ArrayList;
import java.util.Collections;

public class PlayingDeck {

// list of _playingCards
ArrayList<PlayingCard> deckCards = new ArrayList<PlayingCard>();

// constructor
public PlayingDeck() {

//Suits
final int[] _CLUBS = {2,3,4,5,6,7,8,9,10,11,12,13,14};
final int[] _DIAMONDS = {2,3,4,5,6,7,8,9,10,11,12,13,14};
final int[] _HEARTS = {2,3,4,5,6,7,8,9,10,11,12,13,14};
final int[] _SPADES = {2,3,4,5,6,7,8,9,10,11,12,13,14};

final String JA = "Jack";
final String A = "Queen";
final String KI = "King";
final String AC = "Ace";

int[][] _playingCards = new int[4][13];

//filling deckCards of _playingCards
for (int i = 0; i < 4; i++) {
switch(i) {
case 0: _playingCards[0] = _CLUBS;
case 1: _playingCards[1] = _DIAMONDS;
case 2: _playingCards[2] = _HEARTS;
case 3: _playingCards[3] = _SPADES;
}
}

//Aassigning card vales
for (int i = 0; i < _playingCards.length; i++) {
PlayingSuit _suit = null;

switch(i) {
case 0: _suit = PlayingSuit._DIAMONDS;
break;
case 1: _suit = PlayingSuit._HEARTS;
break;
case 2: _suit = PlayingSuit._SPADES;
break;
case 3: _suit = PlayingSuit._CLUBS;
}

for (int k = 2; k < 15; k++) {
String _tempCard = null;

switch(k) {
case 11: _tempCard = JA;
break;
case 12: _tempCard = A;
break;
case 13: _tempCard = KI;
break;
case 14: _tempCard = AC;
break;
default: _tempCard = String.valueOf(k);
}

deckCards.add(new PlayingCard(_suit, _tempCard, 15 - k));

}
}
}

// _playingCards shuffling
public void shuffleDeck() {
Collections.shuffleDeck(deckCards);
}

// taking card from deckCards
public PlayingCard withdraw() {
if(deckCards.isEmpty())
return null;

PlayingCard tempcard = deckCards.get(0);
deckCards.remove(0);

return tempcard;
}

// remove top card
public void withdrawTopCard() {
if(!deckCards.isEmpty())
deckCards.remove(0);
}

// diaplay _playingCards
public void printCards() {
for (int i = 0; i < deckCards.size(); i++) {
System.out.println(deckCards.get(i));
}
}

// retuns total deckCards of _playingCards
public int getDeckCount() {
return deckCards.size();
}
}

----------------------------------------------------------------------------------------------------------------------------------
public enum PlayingSuit {
_HEARTS,_DIAMONDS,_CLUBS,_SPADES,JOKER;
}

-----------------------------------------------------------------------------------------------------------------------------------
import java.util.Scanner;

public class TestDriver {

public static void main(String args[]) {

PlayingDeck _mydeck = new PlayingDeck();
PlayingCard start;
PlayingCard freshCard;
int totalScore = 0;
String lowHigh = "";

Scanner sc = new Scanner(System.in);

_mydeck.shuffleDeck();
System.out.println(_mydeck.getDeckCount());
System.out.println("");

start = _mydeck.withdraw();

while(_mydeck.getDeckCount() > 0) {
freshCard = _mydeck.withdraw();

while(freshCard.compareTo(start) == 0)
freshCard = _mydeck.withdraw();

System.out.println(start);

while(!"HI".equals(lowHigh) && !"LO".equals(lowHigh)) {

if("Q".equals(lowHigh))
break;

System.out.println("HI -> Higher, LO -> Lower, Q -> Quit: ");
lowHigh = sc.next();
}

if("Q".equals(lowHigh))
break;

if((freshCard.compareTo(start) == 1) && "HI".equals(lowHigh)) {
totalScore++;
}

if((freshCard.compareTo(start) == -1) && "LO".equals(lowHigh)) {
totalScore++;
}

start = freshCard;
lowHigh = "";

}

System.out.println(" Your Total Score: " + totalScore);
System.out.println(_mydeck.getDeckCount());

}
}

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