Basically, I have a test class trying out different methods. I'll just post the tester class for now and see if you guys can spot an errors. If you guys can't, then I'll post the other 3 classes. The other classes are for deck, card, and suite. And the program worked and it compared the card's rank correctly, but it was like the same cards each time you run it just like a new deck of cards each time we run it. So I wanted to shuffle it before so I used the shuffle method right after initiializing the deck. And it stopped working and gave me that error.
Quote
Exception in thread "main" java.lang.NullPointerException
at RankCompare.main(RankCompare.java:11)
at RankCompare.main(RankCompare.java:11)
import java.util.*;
public class TestRankCompare{
public static void main(String[] args){
Deck deck1 = new Deck();
deck1.shuffle();
Card card1 = deck1.deal();
Card card2 = deck1.deal();
if (card1.getRank() > card2.getRank()){
System.out.println("The Suit: " + card1.getSuit() + " has a rank of " +
card1.getRank() + " and is greater than the " + card2.getSuit() + "\n which has " +
" the rank of: " +card2.getRank());
}
else{
System.out.println("The Suit: " +card2.getSuit() + " has a rank of " +
card2.getRank() + " and is greater than the " + card1.getSuit() + "\n which has " +
"the rank of " + card1.getRank());
}
}
}


Sign In
Create Account


Back to top









