第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

我的作業(yè) - 洗牌發(fā)牌比大小

package?com.cards;

import?java.util.ArrayList;
import?java.util.List;

public?class?Card?implements?Comparable<Card>?{
	private?String?num;
	private?String?type;
	private?String[]?types?=?{?"黑桃",?"紅桃",?"梅花",?"方片"?};
	private?String[]?cha?=?{?"2",?"3",?"4",?"5",?"6",?"7",?"8",?"9",?"10",?"J",?"Q",?"K",?"A"?};

	public?String?getNum()?{
		return?num;
	}

	public?String?getType()?{
		return?type;
	}

	public?List<String>?changStringToList(String[]?Array)?{
		List<String>?str?=?new?ArrayList<String>();
		for?(int?i?=?0;?i?<?Array.length;?i++)?{
			str.add(Array[i]);
		}
		return?str;
	}
	public?Card(String?type,?String?num)?{
		this.type?=?type;
		this.num?=?num;
	}

	public?void?printCard()?{
		System.out.print(this.type?+?this.num);
	}

	@Override
	public?int?compareTo(Card?card)?{
		//?TODO?Auto-generated?method?stub

		if?(!(this.num.equals(card.num)))?{
			Integer?i?=?this.changStringToList(cha).indexOf(this.num);
			Integer?j?=?this.changStringToList(cha).indexOf(card.num);
			return?i.compareTo(j);
		}?else?{
			Integer?i?=?this.changStringToList(types).indexOf(this.type);
			Integer?j?=?this.changStringToList(types).indexOf(card.type);
			return?i.compareTo(j);
		}
	}
}

package?com.cards;

import?java.util.ArrayList;
import?java.util.List;

public?class?Customer?{
	public?int?ID;
	public?String?name;
	public?List<Card>?cards?=?new?ArrayList<Card>();
	//?public?Cards?card1;
	//?public?Cards?card2;

	public?Customer(int?ID,?String?name)?{
		this.ID?=?ID;
		this.name?=?name;
	}
	public?void?resetCards(){
		cards?=?new?ArrayList<Card>();
	}
	public?void?setCard(Card?cards)?{
		this.cards.add(cards);
	}

}

package?com.cards;

import?java.util.ArrayList;
import?java.util.Collections;
import?java.util.List;
import?java.util.Scanner;

public?class?PlayGames?{
	List<Card>?cards?=?new?ArrayList<Card>();
	List<Customer>?customers?=?new?ArrayList<Customer>();

	public?void?initiateCards()?{
		String[]?types?=?{?"黑桃",?"紅桃",?"梅花",?"方片"?};
		String[]?cha?=?{?"2",?"3",?"4",?"5",?"6",?"7",?"8",?"9",?"10",?"J",?"Q",?"K",?"A"?};
		System.out.println("-------------創(chuàng)建撲克牌--------------");
		for?(int?i?=?0;?i?<?types.length;?i++)?{
			for?(int?j?=?0;?j?<?cha.length;?j++)?{
				cards.add(new?Card(types[i],?cha[j]));
			}
		}
		System.out.println("-------------撲克牌創(chuàng)建成功!--------------");
	}

	public?void?shuffleCards()?{
		Collections.shuffle(cards);
		System.out.println("-------------洗牌結(jié)束!--------------");
	}

	public?void?createCards()?{
		initiateCards();
		for?(Card?card?:?cards)?{
			System.out.print(card.getType()?+?card.getNum()?+?",");
		}
		System.out.println();
		System.out.println("總共有"?+?cards.size()?+?"張牌。");
		shuffleCards();
	}

	public?void?createCustomer()?{
		Scanner?scanner;

		for?(int?i?=?1;?i?<=?2;?i++)?{
			System.out.println("請(qǐng)輸入第"?+?i?+?"位玩家的ID和姓名:");
			System.out.println("輸入ID");
			int?id;
			while?(true)?{
				try?{
					scanner?=?new?Scanner(System.in);
					id?=?scanner.nextInt();
					break;
				}?catch?(Exception?e)?{
					System.out.println("請(qǐng)輸入整數(shù)類(lèi)型的ID!");
					continue;
				}
			}
			System.out.println("輸入姓名");
			String?name?=?scanner.next();
			customers.add(new?Customer(id,?name));
			System.out.println("--------歡迎玩家:"?+?name?+?"------------");
		}

	}

	public?void?sendCards()?{
		System.out.println("-------------開(kāi)始發(fā)牌-----------");
		int?sentNum?=?0;
		//?for?(int?cirecle?=?0;?cirecle?<?cards.size()/customers.size();
		//?cirecle++)?{
		for?(int?cirecle?=?0;?cirecle?<?4?/?customers.size();?cirecle++)?{
			for?(Customer?customer?:?customers)?{
				System.out.println("玩家?"?+?customer.name?+?"?拿牌");
				customer.setCard(cards.get(sentNum));
				sentNum++;
			}
		}
		System.out.println("----------發(fā)牌結(jié)束------------");

	}

	public?void?startGames()?{
		List<Card>?cardsMax?=?new?ArrayList<Card>();

		System.out.println("----------開(kāi)始游戲------------");
		//?取得當(dāng)前玩家手上最大的牌
		for?(Customer?customer?:?customers)?{
			List<Card>?cardMaxOfCustomer?=?new?ArrayList<Card>();
			cardMaxOfCustomer?=?customer.cards;
			Collections.sort(cardMaxOfCustomer);
			Collections.reverse(cardMaxOfCustomer);
			cardsMax.add(customer.cards.get(0));
			System.out.print("玩家:?"?+?customer.name?+?"?最大的手牌為:");
			customer.cards.get(0).printCard();
			System.out.println();
		}
		//?取得最大的牌
		Collections.sort(cardsMax);
		Collections.reverse(cardsMax);
		for?(Customer?customer?:?customers)?{
			if?(customer.cards.contains(cardsMax.get(0)))?{
				System.out.println("-----------玩家:?"?+?customer.name?+?"?獲勝?!---------");
				break;
			}
		}

		//?打印玩家手上各自的牌
		System.out.println("玩家各自的手牌為:");
		for?(Customer?customer?:?customers)?{
			System.out.print(customer.name?+?":");
			for?(Card?card?:?customer.cards)?{
				card.printCard();
				System.out.print("?");
			}
			System.out.println("");
		}
	}

	public?static?void?main(String[]?args)?{
		PlayGames?c?=?new?PlayGames();
		c.createCards();
		c.createCustomer();
		c.sendCards();
		c.startGames();
	}
}

http://img1.sycdn.imooc.com//55cf9f930001cdba05780638.jpg

正在回答

1 回答

不錯(cuò)不錯(cuò)

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

我的作業(yè) - 洗牌發(fā)牌比大小

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)