Hi all,
I'm writing a card game but I can't seem to set the cards in the deck. I'm getting a runtime exception error, whether I first try to set the suit or the rank. Here's my code:
Card.java
public class Card
{
private String suit;
private int rank;
Card()
{
}
public Card(String suit,int rank)
{
this.suit=suit;
this.rank=rank;
}
public void setSuit(String suit)
{
this.suit=suit;
}
public void setRank(int rank)
{
this.rank=rank;
}
Hearts.java
public class Hearts
{
public static void main (String [] args)
{
Player [] players = new Player [3];
Card [] deck = new Card [51];
boolean finish=false;
int roundNo=1;
System.out.println("hmm");
while (finish==false)
{
boolean roundComplete=false;
while (roundComplete==false)
{
System.out.println("h111");
boolean continueGame=true;
for (int i=0;i<deck.length;i++)
{
System.out.println(i);
if ((i>=0)&&(i<13))
{
deck[i].setRank(i);
deck[i].setSuit("d");
System.out.println("yay");
}
I'm having trouble in the loop, where I'm setting the suit and rank. Can anyone spot what's wrong with the code?
Cheers,