About the Java Shuffle Licensing small program

Source: Internet
Author: User
Tags shuffle

Package Play.card;

public class Card {
public String num;
public String suit;
Public Card (String num,string suit) {
This.num = num;
This.suit = suit;
}

Public Card () {
Super ();
}

@Override
Public String toString () {
String str = suit+ "" + num;
return str;
}
}

Package Play.card;

Import java.util.ArrayList;
Import java.util.List;

public class Player {
public String name;
public list<card> cards;
Public Player (String name) {
Super ();
THIS.name = name;
}

Public Player () {
Super ();
}

Get your hands on the cards
public void Getcard (card) {
if (cards = = null) {
cards = new arraylist<card> ();
}
Cards.add (card);
}

@Override
Public String toString () {
Return name + ":" + cards.tostring ();
}
}

Package Play.card;

Import java.util.ArrayList;
Import java.util.Collections;
Import java.util.List;

public class Deskofcard {
list<card> cards;
Create a second hand
public void Initcard () {
String [] nums = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "Ten", "J", "Q", "K"};
String [] suits = {"Block", "Plum Blossom", "peach", "spades"};
cards = new arraylist<card> ();
Create four kinds of cards first

for (int i = 0; i < i++) {
Cards.add (New Card (nums[i%13],suits[i%3]));
}
System.out.println ("------------Create Poker-----------------");
System.out.println ("-------------Poker Creation-------------");
System.out.println ("All cards:");
System.out.println (cards);
}
public static void Main (string[] args) {
Deskofcard test = new Deskofcard ();
Test.initcard ();//initialization
Collections.shuffle (test.cards);//Shuffle
Create a player
Player PL1 = new player ("Cute");
Player PL2 = new player ("Jane");
Player PL3 = new player ("Katte");
Licensing
for (int i = 0; i < i++) {
if (i%3==0) {
Pl1.getcard (Test.cards.get (i));
}
if (i%3==1) {
Pl2.getcard (Test.cards.get (i));
}
if (i%3==2) {
Pl3.getcard (Test.cards.get (i));
}
}
System.out.println ("The player takes the hand is:");
System.out.println (Pl1.tostring ());
System.out.println (Pl2.tostring ());
System.out.println (Pl3.tostring ());

}

}

About the Java Shuffle Licensing small program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.