import java.util.*;
class Cardclass{
public String ID;
public String color;
public Cardclass(String ID , String color){
this.ID = ID;
this.color = color;
}
}
class Card{
static List<Cardclass> newcard;
public Card(){
this.newcard = new ArrayList<Cardclass>();
}
public void add(){
int i;
int j;
int n=0;
String[] IDs=new String[13];
IDs[0] = "A";
IDs[1] = "2";
IDs[2] = "3";
IDs[3] = "4";
IDs[4] = "5";
IDs[5] = "6";
IDs[6] = "7";
IDs[7] = "8";
IDs[8] = "9";
IDs[9] = "10";
IDs[10] = "J";
IDs[11] = "Q";
IDs[12] = "K";
String[] color=new String[4];
color[0] = "Black";
color[1] = "Red";
color[2] = "Plum";
color[3] = "Square";
for(i = 0 ; i < 13 ; i++){
for(j = 0 ; j < 4 ; j++){
Cardclass cc = new Cardclass(IDs[i],color[j]);
newcard.add(cc);
Cardclass outPut = (Cardclass)newcard.get(n);
System.out.println(outPut.ID + " " + outPut.color);
n++;
}
}
}
}
class people extends Card{
public int Num;
public String Name;
public String id;
public String color;
public people(int x , String y ,String newID , String newcolor){
Num = x;
Name = y;
System.out.println("1");
id = newID;
color = newcolor;
}
}
public class tp extends Card{
public static void main(String[] args){
int i;
int j;
int n=0;
Card cd = new Card();
cd.add();
System.out.println("*********************");
Scanner input = new Scanner(System.in);
for(i = 0 ; i < 2 ;i++){
System.out.println("请输入玩家序号");
int newnum = input.nextInt();
System.out.println("请输入玩家名字");
String newname = input.next();
Cardclass newcd = (Cardclass)newcard.get(n); // 第二次执行时候会提示越界
String newID = newcd.ID;
String newcolor = newcd.color;
people newpeople = new people(newnum , newname , newID , newcolor);
System.out.println(newpeople.Num+" "+newpeople.Name+" "+newpeople.id+" "+newpeople.color);
n++;
}
}
}
问题在注释那句 刚刚学不是很懂 - -!
sxian_wang
相关分类