class Card{
private int num, suit;
private static String[] suitArray= {"s", "h", "c", "d", "trees"};
private static int[] numArray=new int[13];
public Card(int suit, int num){ //create cards
this.num=num; //this.num means the num variable in the card class not in the card constructor method parameters
this.suit=suit;
for (int i=0; i<13; i++){ //populate numArray with number 1-13
numArray[i]=i+1;
}
}
public int getNum(){ //get the integer value of a card
return num;
}
class Player{
private Scanner input= new Scanner(System.in);
private Deck deckObj= new Deck();
private Card[] hand;
private int sums, draw, count;
private String player, choice;
public Player(){
hand=new Card[5];
draw=1;
choice="hit";
count=0;
deckObj.displayDeck();
deckObj.shuffle();
deckObj.displayDeck();
}
public void intro(){ //simple introductory sentence to welcome player
System.out.println("Who is brave enough to face the dealer?");
player=input.nextLine();
System.out.println("Good Luck "+player);
}
public int sum(){ //finds sum of the cards in the hand
sums=0;
boolean ace=false;
for (int i=0; i<draw; i++){
if (hand[i].getNum()==1){
ace=true;
sums+=hand[i].getNum();
}
if (ace==true && sums<=11) {
sums+=10;
}
}
return sums;
}
public int playerHand(){ //compile a hand for the player and returns the sum
while (choice.equals("hit")&&sums<21&&draw<=5){ //adds cards until draw is over 5 and sum is greater 21
draw++; //keeps track of number of cards drawn
for (int i=count; i<=draw; i++){
hand[i]=deckObj.draw(); //outofbounds exception?
count++;
}
System.out.println(this.displayHand());
System.out.println("Your sum is "+this.sum()+". Type hit for another card or stay to keep your current sum:");
choice=input.nextLine();
clear();
}
input.close();
return count;
}
Any help would be greatly appreciated.
Edited by ZekeDragon, 08 April 2010 - 12:45 AM.
Please use [code] tags (the # button) when posting code.


Sign In
Create Account

Back to top









