So totally lost here....

I am writing a poker program for a college programming class. I don't want anyone to "do my homework for me" but, I am totally at a loss as to where I have gone wrong. When I instantiate the class and execute the printCard method (code below) it always returns AD.

When I run the debugger (Eclipse version 3.2 if that makes a difference) I get this error: "ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2

JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [../../../src/share/back/util.c:820]"

Here is the code as it currently stands:

public class Card

{

public static final byte TWO=2;

public static final byte THREE=3;

public static final byte FOUR=4;

public static final byte FIVE=5;

public static final byte SIX=6;

public static final byte SEVEN=7;

public static final byte EIGHT=8;

public static final byte NINE=9;

public static final byte TEN=10;

public static final byte JACK=11;

public static final byte QUEEN=12;

public static final byte KING=13;

public static final byte ACE=14;

public static final byte CLUB=101;

public static final byte DIAMOND =102;

public static final byte HEART=103;

public static final byte SPADE=104;

private byte value=0;

private byte suit=0;

public Card() {}

/**

* Creates an instance of Card assigning suits and values.

* @param value The value of the card created.

* @param suit The suit of the card created.

*/

public Card (byte value, byte suit)

{

this.value = value;

this.suit = suit;

}

/**

* Gets the value of the card.

* @return value The value of the card.

*/

public void setValue(int numIn)

{

switch(numIn)

{

case 0: this.value = TWO;

case 1: this.value = THREE;

case 2: this.value = FOUR;

case 3: this.value = FIVE;

case 4: this.value = SIX;

case 5: this.value = SEVEN;

case 6: this.value = EIGHT;

case 7: this.value = NINE;

case 8: this.value = TEN;

case 9: this.value = JACK;

case 10:this.value = QUEEN;

case 11:this.value = KING;

case 12:this.value = ACE;

}

}

/**

* Sets the suit of the card.

* @param suit The suit of the card.

*/

public void setSuit(int numIn)

{

switch(numIn)

{

case 0: this.suit = CLUB;

case 1: this.suit = DIAMOND;

case 2: this.suit = HEART;

case 3: this.suit = SPADE;

}

}

/**

* Prints the description of the card.

*

*/

public String getValue()

{

String val ="";

switch(this.value)

{

case TWO:val = "2";

case THREE: val = "3";

case FOUR: val = "4";

case FIVE: val = "5";

case SIX:val = "6";

case SEVEN: val = "7";

case EIGHT: val = "8";

case NINE: val = "9";

case TEN:val ="10";

case JACK: val = "J";

case QUEEN: val = "Q";

case KING: val = "K";

case ACE:val = "A";

}

return val;

}

/**

* Gets the suit of the card.

* @return suit The suit of the card.

*/

public String getSuit()

{

String tempSuit = "";

switch(this.suit)

{

case CLUB: tempSuit ="C";

case SPADE:tempSuit ="S";

case HEART:tempSuit ="H";

case DIAMOND:tempSuit ="D";

}

return tempSuit;

}

/**

* Sets the suit of the card.

* @param value The value of the card.

*/

public void printCard()

{

System.out.println(getValue()+ getSuit());

}

}

Message was edited by:

jonathan.ownbey

note: the methods and constants were required in the assignment.

Thanks for any help.

[3904 byte] By [jonathan.ownbeya] at [2007-11-26 18:14:22]
# 1

It looks like you forgot to put break statements after each case in your switch statements. Like:

switch(this.suit){

case CLUB:

tempSuit ="C";

break;

case SPADE:

tempSuit ="S";

break;

<etc...>

}

So all of your switches fall through to the last case. Also, use the code tags when you post code, because it hurts my eyes not to have syntax highlighting :-)

sd4139a at 2007-7-9 5:47:44 > top of Java-index,Java Essentials,New To Java...
# 2
How are running this? There's no main method in your Card class.How do you instantiate the Card? Using the default constructor?If you're using Java 5, I'd recommend enum: http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html%
duffymoa at 2007-7-9 5:47:44 > top of Java-index,Java Essentials,New To Java...
# 3
Thank you immensely! That helped greatly. I will use the code tags next time. My apologies.Jon O.
jonathan.ownbeya at 2007-7-9 5:47:45 > top of Java-index,Java Essentials,New To Java...
# 4
I'm using a driver class to instantiate the Card class.
jonathan.ownbeya at 2007-7-9 5:47:45 > top of Java-index,Java Essentials,New To Java...