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("------------------創(chuàng)建玩家---------------------");
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("輸入類型不匹配,請輸入一個(gè)整數(shù)型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();
}
}
添加回答
舉報(bào)
0/150
提交
取消