在我的方法中,我试图在我的主要方法中使用一个声明的常量CLB。该常数在另一个称为Card的类中。当我尝试使用在主类中编写的setSuit方法时,它给我“找不到符号”
我有一门叫做Card ...的班级
public class Card {
private char value;
private char suit;
public String card = "";
final int NOC = 52; //number of cards
final int NOF = 4; //number of faces
final int NOV = 13; //number of values
//SUITS; 3 letter designation
private final char CLB = '\u2663';
private final char SPD = '\u2660';
private final char HRT = '\u2764';
private final char DMN = '\u2666';
//Array of suits and values
public char[] cardSuit = {CLB, SPD, DMN, HRT};
public char[] cardValue = {'A', 'K', 'Q', 'J', 10, 9, 8, 7, 6, 5, 4, 3, 2};
//CONSTRUCTOR
public Card(){}
public Card(char suit, char value)
{
this.suit = suit;
this.value = value;
}
public void setSuit(char s)
{
if (contains(cardSuit, s))
{
suit = s;
}
这是主要的...
public static void main(String[] args) {
Card test = new Card();
test.setSuit(CLB);
我不太确定自己在做什么错,因为在我的理解中,对象测试应该包含这些诉讼。
答案 0 :(得分:2)
声明如下:
public final static char CLB = '\u2663';
并称呼它
Card.CLB
答案 1 :(得分:0)
如果您的主要方法在另一个类中,则需要将CLB设为public(public final char CLB = '\u2663';
),并像这样引用CLB:Card.CLB