BlackJack Help

import java.util.*;

publicclass blackjack

{

privatestaticfinalint DEFAULTROUNDS = 7;

publicstaticvoid main(String[] args)

{

String titlestring ="Blackjack Game by Ali Syed";

//your code.

System.out.println(titlestring);

}

}

class Card

{

//Static constants

publicstaticfinalint CLUB = 0;

publicstaticfinalint DIAMOND = 1;

publicstaticfinalint HEART = 2;

publicstaticfinalint SPADE = 3;

//Member fields

privateint suit;//CLUB through SPADE

privateint 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

publicint value()

{

}

publicboolean isAce(){return rank >= 14;}

public String toString()

{

String rankstring, suitstring;

if (rank < 11)

rankstring ="" + rank;

elseif (rank == 11)

rankstring ="J";

elseif (rank == 12)

rankstring ="Q";

elseif (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. */

elseif (suit == DIAMOND)

suitstring ="\u0004";

elseif (suit == HEART)

suitstring ="\u0003";

else// (suit == SPADE)

suitstring ="\u0006";

return rankstring + suitstring;

}

}

class Hand

{

//Static constants

privatestaticfinalint MAXCOUNT = 20;//Just to be safe we allow large hands.

//Member fields

private Card cards[] =new Card[MAXCOUNT];

privateint count = 0;

int numberofsoftaces = 0;//this is a helper variable that is set by total().

//Constructor

public Hand(){}

//Mutators

publicvoid add(Card crd){cards[count] = crd; count++;}

//Accessors

publicint 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;

}

publicboolean soft()// Returns true if you have an ace counted as 11 rather than 1

{

total();//Call this to set numberofsoftaces;

return (numberofsoftaces > 0);

}

publicboolean busted(){return total()>21;}

public String toString()

{

//Your code.

}

}

class myRandomextends Random

{

publicint nextInt(int lo,int hi)

{

return lo + nextInt(hi-lo);

}

}

class Deck

{

//Static Member fields

publicstatic myRandom randomizer =new myRandom();

//Member fields

private Card[] cards =new Card[52];

privateint count = 0;

//Constructors

public Deck()

{

//Your code

}

//Mutators

publicvoid fill()

{

//Your code

}

publicvoid 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

publicvoid setHand(Hand newhand){hand = newhand;}

//Accessor

publicboolean busted(){return hand.busted();}

publicint total(){return hand.total();}

public String toString()

{

}

//Method

publicvoid play(Deck deck)

{

}

}

[12215 byte] By [prince_alia] at [2007-11-27 7:44:39]
# 1
1 error found:File: C:\Users\Ali\Documents\Dr Java Files\blackjack.java [line: 58]Error: C:\Users\Ali\Documents\Dr Java Files\blackjack.java:58: missing return statement
prince_alia at 2007-7-12 19:25:15 > top of Java-index,Java Essentials,New To Java...
# 2
The error means you don't have a return statement in a method that requires one. Make sure that all possible branches end with a return.Message was edited by: hunter9000
hunter9000a at 2007-7-12 19:25:15 > top of Java-index,Java Essentials,New To Java...
# 3

import java.util.*;

public class blackjack

{

private static final int DEFAULTROUNDS = 7;

public static void main(String[] args)

{

String titlestring = "Blackjack Game by Ali Syed";

//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()

{

} // LINE 58

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()

{

}

//Method

public void play(Deck deck)

{

}

}

prince_alia at 2007-7-12 19:25:15 > top of Java-index,Java Essentials,New To Java...
# 4
ok but i dont know how to do that i am new to Java :S
prince_alia at 2007-7-12 19:25:15 > top of Java-index,Java Essentials,New To Java...
# 5

You have some stubs that you need to add return statements to. Even if it's null or 0 or something.

public int value() {

return -1;// you have to return something, or the compiler will complain

}

hunter9000a at 2007-7-12 19:25:15 > top of Java-index,Java Essentials,New To Java...
# 6
so can you help me go through it please
prince_alia at 2007-7-12 19:25:15 > top of Java-index,Java Essentials,New To Java...
# 7

> so can you help me go through it please

No, sorry, that would equate to me doing your work for you. I showed you what to do to fix the compiler errors. If a method has a return type that isn't void, then you have to return something. Go through and add a return to all those methods. Or better yet, just take out all those stubs and start small. Work on a single part of the assignment at a time. Take a single method and make it do what it's supposed to do. Test it. Move on to the next one. Repeat.

hunter9000a at 2007-7-12 19:25:15 > top of Java-index,Java Essentials,New To Java...
# 8
thxs
prince_alia at 2007-7-12 19:25:15 > top of Java-index,Java Essentials,New To Java...
# 9
i dont know what to returnMessage was edited by: prince_ali
prince_alia at 2007-7-12 19:25:15 > top of Java-index,Java Essentials,New To Java...
# 10
> i dont know what to return> > ...Have a wild guess:public String toString(){//Your code.}
prometheuzza at 2007-7-12 19:25:15 > top of Java-index,Java Essentials,New To Java...
# 11
return toString
prince_alia at 2007-7-12 19:25:15 > top of Java-index,Java Essentials,New To Java...
# 12
> return toStringHow is the class that method is part of supposed to be represented as a String? You need to know what the code is supposed to do before you can make it do that. Can you describe to us in English what the toString method is supposed to return?
hunter9000a at 2007-7-12 19:25:15 > top of Java-index,Java Essentials,New To Java...
# 13
it is is suppose to return the hand total
prince_alia at 2007-7-12 19:25:15 > top of Java-index,Java Essentials,New To Java...
# 14
> it is is suppose to return the hand totalWell, then do so.
prometheuzza at 2007-7-12 19:25:15 > top of Java-index,Java Essentials,New To Java...