public class Card {//Poker class
Private String face;
Private String suit;
The value of the card and the color initialization
Public Card (string face, string suit) {
This.face = face;
This.suit = suit;
}
Output card face value and color
Public String toString () {
Return suit + "" + Face;
}
Public String Getface () {
return face;
}
Public String Getsuit () {
return suit;
}
Shuffle the way
public static void Xipai (card[] deck) {
for (int first = 0; first < deck.length; first++) {
int second = (int) (Math.random () * 52);//randomly Generate 0-51 numbers
Card temp = Deck[first]; The variable that represents this class is itself, an object of its own.
Deck[first] = Deck[second];
Deck[second] = temp;
}
}
Licensing
public static void Fapai (card[] deck) {
Card a[] = new card[52];
Card b[] = new card[52];
Card c[] = new card[52];
Card d[] = new card[52];
for (int i = 0; i < deck.length; i + = 4) {
A[i] = Deck[i];
B[i] = deck[i + 1];
C[i] = deck[i + 2];
D[i] = deck[i + 3];
}
int count = 0;
System.out.print ("A player is licensed \ T");
for (int i = 0; i < deck.length; i + = 4) {
System.out.print (A[i] + "\ t");
count++;
if (count% 13 = = 0) {
System.out.println ("");
}
}
System.out.print ("B player licensed \ T");
for (int i = 0; i < deck.length; i + = 4) {
System.out.print (B[i] + "\ t");
count++;
if (count% 13 = = 0) {
System.out.println ("");
}
}
System.out.print ("C player licensed \ T");
for (int i = 0; i < deck.length; i + = 4) {
System.out.print (C[i] + "\ t");
count++;
if (count% 13 = = 0) {
System.out.println ("");
}
}
System.out.print ("D player licensed \ T");
for (int i = 0; i < deck.length; i + = 4) {
System.out.print (D[i] + "\ t");
count++;
if (count% 13 = = 0) {
System.out.println ("");
}
}
}
}
Test class
public class Demo {
public static void Main (string[] args) {
String [] f={"A", "2", "3", "4", "5", "6", "7", "8", "9", "Ten", "J", "Q", "K"};
String s[]={"Spades", "Red Peach", "Plum", "block"};
Card Deck[]=new card[52]; Object array
for (int i = 0; i < deck.length; i++) {
deck[i] = new Card (f[I, s[I/13]);//Each object in the array must be instantiated separately
System.out.println (Deck[i].tostring ());
}
--Shuffle--********************************
Card Gina[]=new card[52];
Card.xipai (deck);
Shuffle the sequence after
for (int i = 0; i < deck.length; i++) {
System.out.println (Deck[i].tostring ());
}
System.out.println ("***************************************************");
for (int i = 0; i < gina.length; i++) {
Gina[i]=deck[i];
}
--Licensing--********************************
Card.fapai (GINA);
The sequence after the card is issued
for (int i = 0; i < deck.length; i++) {
System.out.println (Gina[i].tostring ());
}
}
}
Bucket Landlord--Jinhua bar--3dmark