import java.util.*; //For Random class
public class blackjack
{
private static final int DEFAULTROUNDS = 7;
public static void main(String[] args)
{
String titlestring = "Blackjack Game by Rudy Rucker, Sept. 19, 2000";
//your code.
System.out.println(titlestring);
}
}
class Card
{
//Static constants
public static final int CLUB = 0;
public static final int DIAMOND = 1;
public static final int HEART = 2;
public static final int SPADE = 3;
//Member fields
private int suit; //CLUB through SPADE
private int rank; //2 through 14; 11-14 are J,Q,K,A
//Constructors
public Card(int irank, int isuit){rank = irank; suit = isuit;}
public Card(){rank = 2; suit = CLUB;}
//Accessors
public int value()
{
//Your code
}
public boolean isAce(){return rank >= 14;}
public String toString()
{
String rankstring, suitstring;
if (rank < 11)
rankstring = "" + rank;
else if (rank == 11)
rankstring = "J";
else if (rank == 12)
rankstring = "Q";
else if (rank == 13)
rankstring = "K";
else //rank == 14
rankstring = "A";
if (suit == CLUB)
suitstring = "\u0005"; /* Instead of "Club", we use a special
symbol that we specify with a four hex digit unicode escape.
We use similar codes fo the other suits. */
else if (suit == DIAMOND)
suitstring = "\u0004";
else if (suit == HEART)
suitstring = "\u0003";
else // (suit == SPADE)
suitstring = "\u0006";
return rankstring + suitstring;
}
}
class Hand
{
//Static constants
private static final int MAXCOUNT = 20; //Just to be safe we allow large hands.
//Member fields
private Card cards[] = new Card[MAXCOUNT];
private int count = 0;
int numberofsoftaces = 0; //this is a helper variable that is set by total().
//Constructor
public Hand(){}
//Mutators
public void add(Card crd){cards[count] = crd; count++;}
//Accessors
public int total()
{
int sum = 0;
numberofsoftaces = 0; //Reset the helper variable.
for (int i=0; i<count; i++)
{
sum += cards[i].value();
if (cards[i].isAce())
numberofsoftaces++;
}
if (sum > 21)
while (numberofsoftaces > 0)
{
sum -= 10;
numberofsoftaces--;
}
return sum;
}
public boolean soft() // Returns true if you have an ace counted as 11 rather than 1
{
total(); //Call this to set numberofsoftaces;
return (numberofsoftaces > 0);
}
public boolean busted(){return total()>21;}
public String toString()
{
//Your code.
}
}
class myRandom extends Random
{
public int nextInt(int lo, int hi)
{
return lo + nextInt(hi-lo);
}
}
class Deck
{
//Static Member fields
public static myRandom randomizer = new myRandom();
//Member fields
private Card[] cards = new Card[52];
private int count = 0;
//Constructors
public Deck()
{
//Your code
}
//Mutators
public void fill()
{
//Your code
}
public void shuffle()
{
for (int i=0; i<count; i++)
{
int swapi = randomizer.nextInt(i, count); //i through count-1
Card temp = cards[i];
cards[i] = cards[swapi];
cards[swapi] = temp;
}
}
//Methods
public Card draw()
{
//Your code
}
public Hand[] deal(int numberofhands, int cardsperhand)
{
Hand hands[] = new Hand[numberofhands];
int j;
for (j=0; j< numberofhands; j++)
hands[j] = new Hand();
for (int i=0; i<cardsperhand; i++)
for (j=0; j< numberofhands; j++)
hands[j].add(draw());
return hands;
}
}
class Player
{
//Member fields
private String name = "";
private Hand hand = new Hand();
//Constructors
public Player(){};
public Player(String iname){name = iname;}
//Mutator
public void setHand(Hand newhand){hand = newhand;}
//Accessor
public boolean busted(){return hand.busted();}
public int total(){return hand.total();}
public String toString()
{
//Your code.
}
//Method
/** Make the play strategy be a looop that does this: keep drawing
cards from the deck as long as your total is 16 or less. If your
total is 17, draw a card if your hand is soft (includes an ace counted
as 11), otherwise do not draw. If your total is 18 or higher do not draw.*/
public void play(Deck deck)
{
//Your code.
}
}