package dfss;
public class Player {
private Integer id;
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}package dfss;
import java.util.Scanner;
public class PokerGame {
public Player [] players;
public PokerGame(){
players=new Player[2];
}
public void createPlayer(){
System.out.println("------------------创建玩家---------------------");
Scanner console=new Scanner(System.in);
Integer id;
for(int i=0;i<2;i++){
System.out.println("请输入第"+(i+1)+"位玩家ID和姓名");
while(true){
try{
System.out.println("输入ID:");
id=console.nextInt();
players[i].setId(id);
break;
}catch(Exception e){
System.out.println("输入类型不匹配,请输入一个整数型ID!!!");
console=new Scanner(System.in);
continue;
}
}
System.out.println("输入姓名:");
String name=console.next();
players[i].setName(name);
}
for(int j=0;j<2;j++){
System.out.println("---欢迎玩家:"+players[j].getName());
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
PokerGame pokerGame=new PokerGame();
pokerGame.createPlayer();
}
}
添加回答
举报
0/150
提交
取消