blackjack help compile errors need help

class Card

{

String name, suit;

int value;

Card(String name, int value, String suit)

{

this.name = name;

this.value = value;

this.suit = suit;

}

void display()

{

System.out.println(name + " of " + suit);

}

public int getValue()

{

return value;

}

}

class Deck

{

Card[] cards;

int x = 0;

Deck()

{

cards = new Card[52];

int[] values = {2,3,4,5,6,7,8,9,10,10,10,10,1};

String[] names = {"two","three","four","five","six","seven","eight","nine","ten","jack","queen","king","ace"};

String[] suits = {"hearts","diamonds","clubs","spades"};

int cnt = 0;

for(int i = 0; i < suits.length; i++)

{

for(int j = 0; j < names.length; j++)

{

cards[cnt] = new Card(names[j],values[j],suits);

cnt++;

}

}

}

void display()

{

for(int i = 0; i < cards.length; i++)

{

cards.display();

}

}

void swap(int a, int b)

{

Card temp = cards[a];

cards[a] = cards;

cards = temp;

}

public Card giveCard()

{

x++;

return cards[x-1];

}

}

import java.util.Random;

class Shuffler

{

static void shuffle(Deck d)

{

Random r = new Random();

for(int i = 0; i < 30; i++)

{

d.swap(r.nextInt(52), r.nextInt(52));

}

}

}

import java.util.Vector;

class Hand

{

Vector hand;

Hand()

{

hand = new Vector();

}

public void getCard(Card c)

{

hand.addElement(c);

}

public int getValue()

{

int cards;

int val;

boolean ace;

val = 0;

ace = false;

cards = getCardCount();

for ( int i = 0; i < cards; i++ )

{

Card card;

int cardVal;

card = (Card)hand.elementAt(i);

cardVal = card.getValue();

if(cardVal == 1)

{

ace = true;

}

val = val + cardVal;

}

if (ace == true && (val + 10)<= 21)

{

val = val + 10;

}

return val;

}

public int getCardCount()

{

return hand.size();

}

}

class Player

{

String name;

Hand hand;

Player(String name, Hand hand);

{

this.name = name;

this.hand = hand;

}

}

public class BlackJack

{

public static void main(String[] args)

{

Card card;

//Deck d = new Deck[52];

//Shuffler.shuffle(d);

Deck d = new Deck();

Shuffler.shuffle(d.cards);

Hand h1 = new Hand();

Hand h2 = new Hand();

Player p1 = new Player("User", h1);

Player p2 = new Player("Computer", h2);

for(int i = 0; i < NUM_OF_CARDS_IN_HAND; i++)

{

h1.getCard(deck.giveCard());

h2.getCard(deck.giveCard());

}

}

Message was edited by:

prince_ali

[3160 byte] By [prince_alia] at [2007-11-27 7:36:46]
# 1
Copy your code from the source not your first post.Paste it in your message.Highlight it.Click code button above message box.This will format your code and make it readable.
floundera at 2007-7-12 19:17:19 > top of Java-index,Java Essentials,New To Java...
# 2
Oh and asking an actual question would be good too.If you get errors then post the error messages as well. We don't read minds.
floundera at 2007-7-12 19:17:19 > top of Java-index,Java Essentials,New To Java...
# 3

class Card

{

String name, suit;

int value;

Card(String name, int value, String suit)

{

this.name = name;

this.value = value;

this.suit = suit;

}

void display()

{

System.out.println(name + " of " + suit);

}

public int getValue()

{

return value;

}

}

class Deck

{

Card[] cards;

int x = 0;

Deck()

{

cards = new Card[52];

int[] values = {2,3,4,5,6,7,8,9,10,10,10,10,1};

String[] names = {"two","three","four","five","six","seven","eight","nine","ten","jack","queen","king","ace"};

String[] suits = {"hearts","diamonds","clubs","spades"};

int cnt = 0;

for(int i = 0; i < suits.length; i++)

{

for(int j = 0; j < names.length; j++)

{

cards[cnt] = new Card(names[j],values[j],suits[i]);

cnt++;

}

}

}

void display()

{

for(int i = 0; i < cards.length; i++)

{

cards[i].display();

}

}

void swap(int a, int b)

{

Card temp = cards[a];

cards[a] = cards[b];

cards[b] = temp;

}

public Card giveCard()

{

x++;

return cards[x-1];

}

}

import java.util.Random;

class Shuffler

{

static void shuffle(Deck d)

{

Random r = new Random();

for(int i = 0; i < 30; i++)

{

d.swap(r.nextInt(52), r.nextInt(52));

}

}

}

import java.util.Vector;

class Hand

{

Vector hand;

Hand()

{

hand = new Vector();

}

public void getCard(Card c)

{

hand.addElement(c);

}

public int getValue()

{

int cards;

int val;

boolean ace;

val = 0;

ace = false;

cards = getCardCount();

for ( int i = 0; i < cards; i++ )

{

Card card;

int cardVal;

card = (Card)hand.elementAt(i);

cardVal = card.getValue();

if(cardVal == 1)

{

ace = true;

}

val = val + cardVal;

}

if (ace == true && (val + 10)<= 21)

{

val = val + 10;

}

return val;

}

public int getCardCount()

{

return hand.size();

}

}

class Player

{

String name;

Hand hand;

Player(String name, Hand hand);

{

this.name = name;

this.hand = hand;

}

}

This is what i've done so far, i need help getting blackjack to give the 2 players cards, how to add them and how to determine a winner.

public class BlackJack

{

public static void main(String[] args)

{

Card card;

//Deck d = new Deck[52];

//Shuffler.shuffle(d);

Deck d = new Deck();

Shuffler.shuffle(d.cards);

Hand h1 = new Hand();

Hand h2 = new Hand();

Player p1 = new Player("User", h1);

Player p2 = new Player("Computer", h2);

for(int i = 0; i < NUM_OF_CARDS_IN_HAND; i++)

{

h1.getCard(deck.giveCard());

h2.getCard(deck.giveCard());

}

}

prince_alia at 2007-7-12 19:17:19 > top of Java-index,Java Essentials,New To Java...
# 4

File: C:\Users\Ali\Documents\Dr Java Files\Card.java [line: 77]

Error: C:\Users\Ali\Documents\Dr Java Files\Card.java:77: class, interface, or enum expected

File: C:\Users\Ali\Documents\Dr Java Files\Card.java [line: 94]

Error: C:\Users\Ali\Documents\Dr Java Files\Card.java:94: class, interface, or enum expected

File: C:\Users\Ali\Documents\Dr Java Files\Card.java [line: 166]

Error: C:\Users\Ali\Documents\Dr Java Files\Card.java:166: class, interface, or enum expected

File: C:\Users\Ali\Documents\Dr Java Files\Card.java [line: 166]

Error: C:\Users\Ali\Documents\Dr Java Files\Card.java:166: unclosed character literal

File: C:\Users\Ali\Documents\Dr Java Files\Card.java [line: 188]

Error: C:\Users\Ali\Documents\Dr Java Files\Card.java:188: reached end of file while parsing

prince_alia at 2007-7-12 19:17:19 > top of Java-index,Java Essentials,New To Java...
# 5
those r the errors im getting
prince_alia at 2007-7-12 19:17:20 > top of Java-index,Java Essentials,New To Java...
# 6
> File: C:\Users\Ali\Documents\Dr Java Files\Card.java [line: 77]Since the Card class doesn't have 77 lines, I assume you have all your class in the one file.Please indicate which is line 77.
floundera at 2007-7-12 19:17:20 > top of Java-index,Java Essentials,New To Java...
# 7
Sorry here the lines compile errors happenline 77: import java.util.Random;line 94:import java.util.Vector;line 166: fixed errorline 188: } last brace
prince_alia at 2007-7-12 19:17:20 > top of Java-index,Java Essentials,New To Java...
# 8
Import statements need to be at the top of the file. Since you have all you classes in the single file you cannot place theimport statements above the classes. Try separating each class out into it's own file.
floundera at 2007-7-12 19:17:20 > top of Java-index,Java Essentials,New To Java...
# 9

i did that now i get another 9 errors in my blackjack class

9 errors and 1 warning found:

--

*** Errors ***

--

File: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java [line: 1]

Error: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java:1: class BlackJack is public, should be declared in a file named BlackJack.java

File: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java [line: 9]

Error: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java:9: shuffle(Deck) in Shuffler cannot be applied to (Card[])

File: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java [line: 13]

Error: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java:13: cannot find symbol

symbol : class Player

location: class BlackJack

File: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java [line: 13]

Error: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java:13: cannot find symbol

symbol : class Player

location: class BlackJack

File: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java [line: 14]

Error: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java:14: cannot find symbol

symbol : class Player

location: class BlackJack

File: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java [line: 14]

Error: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java:14: cannot find symbol

symbol : class Player

location: class BlackJack

File: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java [line: 16]

Error: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java:16: cannot find symbol

symbol : variable NUM_OF_CARDS_IN_HAND

location: class BlackJack

File: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java [line: 18]

Error: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java:18: cannot find symbol

symbol : variable deck

location: class BlackJack

File: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java [line: 19]

Error: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java:19: cannot find symbol

symbol : variable deck

location: class BlackJack

-

** Warning **

-

File: C:\Users\Ali\Documents\Dr Java Files\Hand.java [line: 14]

Warning: C:\Users\Ali\Documents\Dr Java Files\Hand.java:14: warning: [unchecked] unchecked call to addElement(E) as a member of the raw type java.util.Vector

prince_alia at 2007-7-12 19:17:20 > top of Java-index,Java Essentials,New To Java...
# 10
blackjackMessage was edited by: prince_ali
prince_alia at 2007-7-12 19:17:20 > top of Java-index,Java Essentials,New To Java...
# 11

public class BlackJack

{

public static void main(String[] args)

{

Card card;

//Deck d = new Deck[52];

//Shuffler.shuffle(d);

Deck d = new Deck();

Shuffler.shuffle(d.cards);

Hand h1 = new Hand();

Hand h2 = new Hand();

Player p1 = new Player("User", h1);

Player p2 = new Player("Computer", h2);

for(int i = 0; i < NUM_OF_CARDS_IN_HAND; i++)

{

h1.getCard(deck.giveCard());

h2.getCard(deck.giveCard());

}

}

prince_alia at 2007-7-12 19:17:20 > top of Java-index,Java Essentials,New To Java...
# 12
> Error: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java:1: class BlackJack is public, should be declared in a file named BlackJack.javaError messages can be very informative. What do you think that "class Blackjack should be declared in a file named BlackJack.java" means?
floundera at 2007-7-12 19:17:20 > top of Java-index,Java Essentials,New To Java...
# 13
i fixed that problem i saved it wrong file uhhh now i got 8 C:\Users\Ali\Documents\Dr Java Files\Blackjack.java [line: 9]Error: C:\Users\Ali\Documents\Dr Java Files\Blackjack.java:9: shuffle(Deck) in Shuffler cannot be applied to (Card[]) Shuffler.shuffle(d.cards);
prince_alia at 2007-7-12 19:17:20 > top of Java-index,Java Essentials,New To Java...
# 14
Once again the error message is very informative. You have a method called shufle in the Shuffler class that accepts aDeck object as a parameter but you are try to pass an array of Card objects.Deck != Card[]
floundera at 2007-7-12 19:17:20 > top of Java-index,Java Essentials,New To Java...