/**
* Cards.java stores the values of 52 playing cards.
*
* @author Melissa Gendron
* @version 1/14/09
*/
import java.util.Random;
public class Cards
{
//************************************************************************
// Create the enumerated type to determine the each card face
//************************************************************************
enum Card {ace, two, three, four, five, six, seven, eight, nine, ten,
jack, queen, king, error}
public static void main(String[] args)
{
//*********************************************************************
//Initial variable declarations
//*********************************************************************
int card = 1; //used to determine which card, 1-13, to draw
int suit = 1; //used to determine which suit the card it
Card c = Card.ace; //creates an enum d of type Card and gives it the
//initial value of "ace"
//*****************************************************************
//This switch sets the value of the enumerated type c showing
//the face value of the card.
//*****************************************************************
switch(card)
{
case 1: c = Card.ace; break;
case 2: c = Card.two; break;
case 3: c = Card.three; break;
case 4: c = Card.four; break;
case 5: c = Card.five; break;
case 6: c = Card.six; break;
case 7: c = Card.seven; break;
case 8: c = Card.eight; break;
case 9: c = Card.nine; break;
case 10: c = Card.ten; break;
case 11: c = Card.jack; break;
case 12: c = Card.queen; break;
case 13: c = Card.king; break;
default: c = Card.error; break;
}
//*****************************************************************
//This switch sets the value of the enumerated type for printing
//the chosen suit of the card.
//*****************************************************************
switch(suit)
{
case 1: System.out.println(" of spades");
case 2: System.out.println(" of clubs");
case 3: System.out.println(" of hearts");
case 4: System.out.println(" of diamonds");
default: System.out.println(); break;
}
}
}
Hello I have question regarding a program I am supposed to create.
We are supposed to: Design and implement a class called Card that represents a standard playing card. Each card has a suit and a face value.
And I am supposed to create a driver program that plays blackjack with the user.
What I'm wondering is, how can I make the switch statments of the card's face and suit value, print as a random generated number without doubling up? (like ace of heart x2)
I have learned about enums as well as basic switch statements. I have not learned about arrays.
I have not started the blackjack runner because I'm not sure how to create a correct shuffle and deal method, or at least a dealing method that ensure no glitches (repeated cards).
I already forsee a problem with my ace value because in blackjack it can count as 1 or 11, so I'm not sure if a user accepted loop can boolean the value into one or the other according to what the user wants, or if the circumstances force it, such as having an Ace, Jack, and 3, so ace must be a 1 to continue.
Can anybody help me with a skeleton of example or what I need for my program?
I use BlueJ, and I have only used Java for 4 months.
This post has been edited by Cuzenu: 14 January 2009 - 06:59 PM

New Topic/Question
Reply




MultiQuote






|