java - Having trouble creating Card class -
im having trouble converting r[rank] string. eclipse keeps saying needs resolved array. having trouble cards[13*i + j] = new card(i, j); keeps saying cannot resolved variable. heres code...
public class card { private string suit; private string rank; private static string[] s = { "hearts", "spades", "diamonds", "clubs" }; private static string[] r = { "ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king" }; public card(int suit, int deck){ for(int = 0; < 4; i++) { for(int j = 0; j < 13; j++){ cards[13*i + j] = new card(i, j); } } } public card(string r, string s, string suit){ for(int rank = 0; rank < r.length(); rank+=1){ if( rank.equals(r[rank]) ){ this.rank = r+1; } } this.suit = suit; } public string getsuit(){ return suit; } public void setsuit(string a, string suit) { this.suit = suit; } public string getrank(){ return rank; } public void setrank( string s, string rank){ this.rank= rank; } public string tostring(){ return string.valueof(this.getrank()) + string.valueof(this.getsuit().charat(0)); } }
public class deck {
private card[] deck; private int indeck; private final int size_of_deck = 52; private int currentcard; public deck(){ deck = new card[deck]; } private void init(){ } public void shuffle(int num){ int i,j,k; (k = 0; k < num; k++) { = (int) (size_of_deck * math.random()*100); j = (int) (size_of_deck * math.random()*100); card tmp = deck[i]; deck[i] = deck[j]; deck[j] = tmp; } currentcard = 0; } public card getcard(){ if (currentcard<size_of_deck) { return deck[currentcard++]; } else { system.out.print("out of cards error"); return null; } } public int totalcards(){ return size_of_deck ;}
}
you never initialize card array... try along lines of before create each individual object loops.
card[] cards = new card[52];
Comments
Post a Comment