1234
1234

Reputation: 51

Cannot find symbol in java, ADT card application

I've been trying to create a card application to complete a perfect shuffle. I am being met with the error above within this segment of code.

  public class Deck {


private List<Card> cards;


private int size;//number of cards in deck


public Deck(String[] faces, String[] suits, int[] values){
   cards = new ArrayList<Card>();
   for(String suit: suits) 
       for(int value = 0; value < values.length; value++){
           Card a = new Card(faces[face], suit, values[face]);
           cards.add(a);
       }
   size = cards.size();

}//ends deck

More specifically this line, in reference to the face variable.

               Card a = new Card(faces[face], suit, values[face]);

I have created the variable face in another class i have stored in the application called Card.

public class Card {


private String suit;


private String face;


private int value;



public Card(String cardFace, String cardSuit, int cardValue){
    face = cardFace;
    suit = cardSuit;
    value = cardValue;
}//ends Card

public String suit(){

return suit;
}//ends suit

public String face(){

return face;
}//ends face

Im sure this is an easy fix just looking a point in the right direction, thanks.

Upvotes: 1

Views: 108

Answers (2)

Arvind Kumar Avinash
Arvind Kumar Avinash

Reputation: 79550

Replace

for(int value = 0; value < values.length; value++){
   Card a = new Card(faces[face], suit, values[face]);
   cards.add(a);
}

with

for(int value = 0; value < values.length && value < faces.length; value++){
   Card a = new Card(faces[value], suit, values[value]);
   cards.add(a);
}

The following issues have been addressed in the code given above:

  1. Using the loop counter, value as the index value.
  2. Checking the length of both, values and faces arrays because the values from each of these arrays are being accessed using the loop counter, value.

Upvotes: 1

Karim SNOUSSI
Karim SNOUSSI

Reputation: 109

Card a = new Card(faces[face], suit, values[face]);

face is not defined in faces[face] & values[face]

Upvotes: 0

Related Questions