亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

誰能幫我把比較大小寫好,并確定最后誰贏了??

package?cardPlay;

public?class?card?{
public?String?color;
public?String?num;
public?card(String?color,String?num){
	this.color=color;
	this.num=num;
}
}
package?cardPlay;

import?java.util.HashSet;
import?java.util.Set;

public?class?player?{
public?int?id;
public??String?name;
public?Set?cards;
public?player(int?id,String?name){
	this.id=id;
	this.name=name;
	this.cards=new?HashSet();
}
}
import?java.util.Arrays;
import?java.util.Comparator;
import?java.util.List;
/**
?*?比較規則
?*?@author?jelly
?*
?*/
public?class?Compare?implements?Comparator<card>?{
?
????@Override
????public?int?compare(card?o1,card?o2)?{
?
????????List<String>?nums?=?Arrays.asList("2",?"3",?"4",?"5",?"6",?"7",?"8",
????????????????"9",?"J",?"Q",?"K",?"A");
????????List<String>?color?=?Arrays.asList("方塊",?"梅花",?"紅桃",?"黑桃");
????????if?(nums.indexOf(o1.num)?==?nums.indexOf(o2.num))
????????????return?(((Integer)?(color.indexOf(o1.color)))
????????????????????.compareTo((Integer)?(color.indexOf(o2.color))));
????????else?{
????????????return?(((Integer)?nums.indexOf(o1.color)))
????????????????????.compareTo(((Integer)?nums.indexOf(o2.color)));
????????}
????}
}
package?cardPlay;

import?java.util.*;



public?class?Text?{
public?List<card>??cardList=new?ArrayList<card>()?;
public?String[]?nums={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
public?String[]?colors={"黑桃","紅桃","梅花","方塊"};

//創建卡牌
public?void?cardAdd(){
for(int?i=0;i<4;i++){
for(int?j=0;j<13;j++){
	card?c=new?card((colors[i]),(nums[j]));
	cardList.add(c);
}	
}
System.out.println("創建卡牌成功");
for(card?x:cardList)
	System.out.print(x.color+x.num+",");
//for(int?k=0;k<52;k++){
//	
//card?temp=(card)cardList.get(k);
//System.out.print(temp.color+temp.num+"?");
//}
System.out.println();}
//洗牌
public?void?change(){
	Random?random=new?Random();
	for(int?i=0;i<4;i++){
		int?k=cardList.size();
		Integer?j=random.nextInt(k);
		card?temp=(card)cardList.get(j);
		cardList.remove(temp);
		cardList.add(i,temp);
	}
	System.out.println("洗牌結束");

}
//創建玩家
public?void?playerAdd(){
	int?i=0;
	while(i<1){

	try{		System.out.println("輸入第一個玩家ID");??
	Scanner?scan=new?Scanner(System.in);
		int?id1=scan.nextInt();
		System.out.println("輸入第一個玩家姓名");
		String?name1=scan.next();
		player?player1=new?player(id1,name1);
	i++;}catch(Exception?e){
		System.out.println("請輸入整數數字");
	}}
	

	i=0;
	while(i<1){
	try{	System.out.println("輸入第二個玩家ID");
	Scanner?scan=new?Scanner(System.in);
	int	id2=scan.nextInt();
	System.out.println("輸入第二個玩家姓名");
	String?name2=scan.next();
	player?player2=new?player(id2,name2);
	i++;}catch(Exception?e){
		System.out.println("請輸入整數數字");
	}}


	
}
//比較大小
public?void?comparator(){
????Compare?compare?=?new?Compare();
List<card>?com=new?ArrayList<card>();
com.add(cardList.get(0));
com.add(cardList.get(1));
com.add(cardList.get(2));
com.add(cardList.get(3));
Collections.sort(com,compare);
for(card?x:com)
System.out.println(x.num+x.color);
	
}

	


public?static?void?main(String[]?args){
	Text?text=new?Text();
	text.cardAdd();
	text.change();
//	text.playerAdd();
text.comparator();
}}


正在回答

1 回答

哪有閑工夫幫你寫這種基礎代碼,你應該自己寫,遇到問題再來問

2 回復 有任何疑惑可以回復我~
#1

慕粉4401746 提問者

非常感謝!
2017-02-11 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

誰能幫我把比較大小寫好,并確定最后誰贏了??

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號