package?pokerGame;
import?java.util.List;
public?class?Player?{
private?Integer?id;
private?String?name;
private?List<Poker>?playerPokerList;
public?List<Poker>?getPlayerPokerList()?{
return?playerPokerList;
}
public?void?setPlayerPokerList(List<Poker>?playerPokerList)?{
this.playerPokerList?=?playerPokerList;
}
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?pokerGame;
import?java.util.ArrayList;
import?java.util.Arrays;
import?java.util.Collections;
import?java.util.HashMap;
import?java.util.List;
import?java.util.Map;
import?java.util.Scanner;
public?class?PokerGame?{
public?List<Poker>?pokerList;
public?Map<Integer,List>?playersPokerList;
public?Player?[]?players;
public?PokerGame(){
pokerList=new?ArrayList<Poker>();//一副撲克牌
playersPokerList=new?HashMap<Integer,List>();//玩家手牌集合?
players=new?Player[2];
}
//創(chuàng)建玩家
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("輸入類型不匹配,請輸入一個整數(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();
}
}
2016-05-15
你的try語句把int類型當異常捕獲了