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

📄 iomanager.java

📁 Produce Java classes to shuffle the 52 cards when input the number of desired swaps within the range
💻 JAVA
字号:
import java.util.*;
public class IOManager
{

	//--------------FIELDS------------
	private int index1;
	private int index2;
	private Pack pack;
	private int swapno;
	//Create Scanner class instance
	public static Scanner input = new Scanner(System.in);

	//-------------METHOD-------------
	public void shuffle()
	{
		//Input the times to swap
		System.out.println("Input the desired number of swaps with the range of 1 to 1000:");
		System.out.println("Integer between 1 and 1000 (inclusive)");
		System.out.println("=================================================================");
		int swapno = input.nextInt();
		
		//Check the range of swapno
		while (swapno < 1 || swapno > 1000)
		{
			System.out.println("Error: Input " + swapno + " out of range, try again!");
			swapno = input.nextInt();
		}

		//Output the result before shuffle
		System.out.println("\nBefore shuffle:");
		//Creat instance of Pack
		pack = new Pack();
		pack.initialize();
		Card[] array_before = pack.getArray();
		//Call method to output the result
		outputResult(array_before);

		for (int i = 0; i < swapno; i++)
		{
			//Generate random number
			index1 = (int)(Math.random() * 52);
			index2 = (int)(Math.random() * 52);
			pack.swap(index1, index2);
		}

		//Output the result after shuffle
		System.out.println("\n\n\nAfter shuffle:");
		Card[] array_after = pack.getArray();
		//Call method to output the result
		outputResult(array_after);
		}

	//Output the result in four rows
	public void outputResult(Card[] array)
	{
		for (int i = 0; i < 13; i++)
		{
			System.out.print(array[i] + "");
		}
		System.out.print("\n");
		for (int i = 13; i < 26; i++)
		{
			System.out.print(array[i] + "");
		}
		System.out.print("\n");
		for (int i = 26; i < 39; i++)
		{
			System.out.print(array[i] + "");
		}
		System.out.print("\n");
		for (int i = 39; i < 52; i++)
		{
			System.out.print(array[i] + "");
		}
	}
}

⌨️ 快捷键说明

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