用Java表示卡的类? [英] Class for representing a card in Java?
本文介绍了用Java表示卡的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public class Card {
public int suit; //值1-4代表西装
public int value; //值1-13表示值(即2,J)
public Card(int suit,int value){
//尚未实现
}
}
另外,在Java中有一个像C ++的枚举数据结构的好方法,因为这将是
解决方案
public enum Suite {
HEART ,DIAMOND,CLUB,SPADE
}
public enum Value {
TWO,THREE,...,JACK,QUEEN,KING,ACE
}
其余的你可以弄清楚。
I'm making a blackjack program in Java, and I was starting to write the class declaration for an object Card. Will this be sufficient, or are there some methods I should have that I'm glossing over?
public class Card {
public int suit; //Value 1-4 to represent suit
public int value; //Value 1-13 to represent value (i.e. 2, J)
public Card(int suit, int value) {
//Not yet implemented
}
}
Also, is there a good way to have an something like C++'s enum data structure in Java, because that would be nice for card names and suits?
解决方案
public enum Suite {
HEART, DIAMOND, CLUB, SPADE
}
public enum Value {
TWO, THREE, ... , JACK, QUEEN, KING, ACE
}
and the rest you can figure out.
这篇关于用Java表示卡的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文