Preface all lazy Write, all 1:30 A.M., directly put the code up code:
1 Packagecom.day16.list;2 3 Importjava.util.LinkedList;4 ImportJava.util.Random;5 6 /**7 * Class Description:8 * 9 * @authorAuthor: ChenyanlongTen * @versionCreation Date: October 29, 2017 One */ A - //Poker Class - classPoker { the -String color;//Color -String num;//points - + //Construction Method - PublicPoker (string color, string num) { + Super(); A This. color =color; at This. num =num; - } - - //rewrite ToString () - @Override - PublicString toString () { in returncolor+num; - } to + } - the Public classDemo { * $ Public Static voidMain (string[] args) {Panax Notoginseng //instantiating a Collection object -LinkedList pockers=Createpoker (); theFlushpockes (pockers);//Shuffle +Showpoker (pockers);//show how many cards A the } + - //how to generate poker $ Public StaticLinkedList Createpoker () { $ //This collection is used to store poker objects -LinkedList list=NewLinkedList (); - //define an array to store all the suits and points theString[] colors={"Black", "Red Peach", "Plum", "block"}; -String[] nums={"A", "2", "3", "4", "5", "6", "7", "8", "9", "Ten", "J", "Q", "K"};Wuyi the //add a poker in a collection - for(inti=0;i<nums.length;i++){ Wu for(intj=0;j<colors.length;j++){ -List.add (NewPoker (Colors[j],nums[i])); About } $ } - returnlist; - } - A //Shuffle the function + Public Static voidflushpockes (LinkedList pockers) { the //creating random Objects -Random random=NewRandom (); $ for(inti=0;i<100;i++){ the //randomly generates two index values the intA=Random.nextint (Pockers.size ()); the intb=Random.nextint (Pockers.size ()); the //remove two cards based on index value -Poker a1=(Poker) Pockers.get (a); inPoker b1=(Poker) pockers.get (b); the Pockers.set (A, B1); the Pockers.set (b, A1); About } the } the the //Show Poker + Public Static voidShowpoker (LinkedList pockers) { - for(intI=0;i<pockers.size (); i++){ theSystem.out.print ("" +Pockers.get (i)); Bayi //line Break the if(i%10==9){ the System.out.println (); - } - } the System.out.println (); theSystem.out.println ("Number of Cards:" +pockers.size ());//show how many cards the } the -}
Operating effect:
java generates poker----basic Java Learning Summary