D
David
I am making a random card generator program:
I am getting this error when i run my program:
java.lang.IncompatibleClassChangeError
at Project4A2.main(Project4A2.java:20)
Exception in thread "main"
Here's my code. Please help. Also, take a look at the static
variables. I don't really know what they mean. I just got an error
when I compiled the program without it.
*********************************************************
import java.util.Random;
class Project4a
{
public static void main (String [] args)
{
// Use to get random numbers
Random generator = new Random();
// Print out to screen
System.out.println ("Dealing 20 random cards: ");
// repeat this loop 20 times to get 20 cards
for (int i=1; i<=20; i++)
{
// get random numbers for suit and faceValue
int suit = generator.nextInt(4) +1;
int faceValue = generator.nextInt(13) +1;
Card myCard = new Card (suit, faceValue);
// print card
System.out.println (myCard);
}
}
}
************************************************
Here's another part of my code:
************************************************
// import classes
import java.util.Random;
class Card
{
// declare variables
private static int suit;
private static int faceValue;
String cardType;
String suitType;
// constructor
public Card (int suit, int faceValue)
{
// call methods
suit = Card.getSuit();
faceValue = Card.getFaceValue();
}
// gets value for suit
public static int getSuit()
{
return suit;
}
// gets value for faceValue
public static int getFaceValue()
{
return faceValue;
}
// decides the suit and card according to the random number picked
public String toString(int suit, int faceValue)
{
if (suit == 1)
suitType = "Heart";
else if (suit == 2)
suitType = "Diamond";
else if (suit == 3)
suitType = "Club";
else
suitType = "Spade";
switch (faceValue)
{
case 1:
cardType = "Ace";
break;
case 2:
cardType = "2";
break;
case 3:
cardType = "3";
break;
case 4:
cardType = "4";
break;
case 5:
cardType = "5";
break;
case 6:
cardType = "6";
break;
case 7:
cardType = "7";
break;
case 8:
cardType = "8";
break;
case 9:
cardType = "9";
break;
case 10:
cardType = "10";
break;
case 11:
cardType = "Jack";
break;
case 12:
cardType = "Queen";
break;
case 13:
cardType = "King";
break;
}
// returns string
return (suitType + "\t" + cardType);
}
}
****************************************
If you see any other errors in this program, please let me know,
because I'm not very good as of yet. Thanks for the help.
I am getting this error when i run my program:
java.lang.IncompatibleClassChangeError
at Project4A2.main(Project4A2.java:20)
Exception in thread "main"
Here's my code. Please help. Also, take a look at the static
variables. I don't really know what they mean. I just got an error
when I compiled the program without it.
*********************************************************
import java.util.Random;
class Project4a
{
public static void main (String [] args)
{
// Use to get random numbers
Random generator = new Random();
// Print out to screen
System.out.println ("Dealing 20 random cards: ");
// repeat this loop 20 times to get 20 cards
for (int i=1; i<=20; i++)
{
// get random numbers for suit and faceValue
int suit = generator.nextInt(4) +1;
int faceValue = generator.nextInt(13) +1;
Card myCard = new Card (suit, faceValue);
// print card
System.out.println (myCard);
}
}
}
************************************************
Here's another part of my code:
************************************************
// import classes
import java.util.Random;
class Card
{
// declare variables
private static int suit;
private static int faceValue;
String cardType;
String suitType;
// constructor
public Card (int suit, int faceValue)
{
// call methods
suit = Card.getSuit();
faceValue = Card.getFaceValue();
}
// gets value for suit
public static int getSuit()
{
return suit;
}
// gets value for faceValue
public static int getFaceValue()
{
return faceValue;
}
// decides the suit and card according to the random number picked
public String toString(int suit, int faceValue)
{
if (suit == 1)
suitType = "Heart";
else if (suit == 2)
suitType = "Diamond";
else if (suit == 3)
suitType = "Club";
else
suitType = "Spade";
switch (faceValue)
{
case 1:
cardType = "Ace";
break;
case 2:
cardType = "2";
break;
case 3:
cardType = "3";
break;
case 4:
cardType = "4";
break;
case 5:
cardType = "5";
break;
case 6:
cardType = "6";
break;
case 7:
cardType = "7";
break;
case 8:
cardType = "8";
break;
case 9:
cardType = "9";
break;
case 10:
cardType = "10";
break;
case 11:
cardType = "Jack";
break;
case 12:
cardType = "Queen";
break;
case 13:
cardType = "King";
break;
}
// returns string
return (suitType + "\t" + cardType);
}
}
****************************************
If you see any other errors in this program, please let me know,
because I'm not very good as of yet. Thanks for the help.