⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pack.java

📁 Produce Java classes to shuffle the 52 cards when input the number of desired swaps within the range
💻 JAVA
字号:
public class Pack
{

	//-------------FIELDS-------------
	private String value_;
	private String suit_;
	private int quotient;
	private int remainder;
	private Card[] cardArray_;

	//-----------CONSTRACT------------
	public Pack()
	{
		//Create a array with 52 elements
		cardArray_ = new Card[52];
	}

	//-------------METHOD-------------
	public void initialize() {
		for (int i=0; i<52; i++) {
			quotient =i/13;
			remainder =i%13;

			//Switch case to give the suit
			switch (quotient)
			{
				case 0: suit_ = "Spd";
					break;
				case 1: suit_ = "Hrt";
					break;
				case 2: suit_ = "Dmd";
					break;
				case 3: suit_ = "Clb";
					break;
			}

			//Switch casse to give the value
			switch (remainder)
			{
				case 0: value_ = "2";
					break;
				case 1: value_ = "3";
					break;
				case 2: value_ = "4";
					break;
				case 3: value_ = "5";
					break;
				case 4: value_ = "6";
					break;
				case 5: value_ = "7";
					break;
				case 6: value_ = "8";
					break;
				case 7: value_ = "9";
					break;
				case 8: value_ = "10";
					break;
				case 9: value_ = "J";
					break;
				case 10: value_ = "Q";
					break;
				case 11: value_ = "K";
					break;
				case 12: value_ = "A";
					break;
			}

		//Create an instance of card
		Card card = new Card(value_, suit_);
		cardArray_[i] = card;
		}
	}

	public void swap(int index1, int index2)
	{
		Card swap_num1, swap_num2;
		//Exchange the value of two cards
		swap_num1 = cardArray_[index1];
		swap_num2 = cardArray_[index2];
		cardArray_[index1] = swap_num2;
		cardArray_[index2] = swap_num1;
	}

	//Get cardArray_
	public Card[] getArray()
	{
	return cardArray_;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -