1 PackageDou_di_zhu;2 3 Importjava.util.ArrayList;4 Importjava.util.Collection;5 Importjava.util.Collections;6 ImportJava.util.HashMap;7 ImportJava.util.TreeSet;8 9 /**Ten * Ideas: One * A: Create a HashMap collection A * B: Create a ArrayList collection - * C: Create a suit array and an array of points - * D: Store numbers in HashMap and store the corresponding cards from 0 onwards the * Also store the number in ArrayList - * E: Shuffle (Wash is numbered) - * F: The card is issued (also the number of the hair, in order to ensure that the number is sorted, create TreeSet collection receive) - * G: Look at the card (Traverse TreeSet collection, get the number, find the corresponding card in the HashMap) + * @authorUser - * + */ A Public classPokerDemo1 { at Public Static voidMain (string[] args) { - //Create a HashMap collection -Hashmap<integer, string> HM =NewHashmap<integer,string>(); - - //Create a ArrayList collection -arraylist<integer> array =NewArraylist<integer>(); in - //creating suit arrays and array of points to //define a suit array +string[] colors = {"♠", "♥", "♣", "♦"}; - //define an array of points thestring[] numbers = {"3", "4", "5", "6", "7", "8", *"9", "Ten", "J", "Q", "K", "A", "2"}; $ Panax Notoginseng //Starting from 0, store the number in the HashMap and store the corresponding card, and store the number in the ArrayList. - intindex = 0; the for(String number:numbers) { + for(String color:colors) { AString Poker =color.concat (number); the hm.put (index, poker); + Array.add (index); -index++; $ } $ } -Hm.put (Index, "Xiao Wang"); - Array.add (index); theindex++; -Hm.put (Index, "King"));Wuyi Array.add (index); the - //Shuffle (Wash is numbered) Wu collections.shuffle (array); - About //The card is issued (the number is also numbered, in order to ensure that the number is sorted, create TreeSet collection receive) $Treeset<integer> fanbingbing =NewTreeset<integer>(); -Treeset<integer> Sunhang =NewTreeset<integer>(); -Treeset<integer> Linqingxia =NewTreeset<integer>(); -Treeset<integer> Dipai =NewTreeset<integer>(); A + for(intx = 0; x < Array.size (); X + +) { the if(x >= array.size ()-3) { - Dipai.add (Array.get (x)); $}Else if(x%3 = = 0) { the Fanbingbing.add (Array.get (x)); the}Else if(x%3 = = 1) { the Sunhang.add (Array.get (x)); the}Else if(x%3 = = 2) { - Linqingxia.add (Array.get (x)); in } the } the About //look at the cards (traverse the TreeSet collection, get the numbers, find the corresponding cards in the HashMap) theLookpoker ("Fan Bingbing", FANBINGBING,HM); theLookpoker ("Sun Hang", SUNHANG,HM); theLookpoker ("Brigitte", LINQINGXIA,HM); +Lookpoker ("Hole cards", DIPAI,HM); - } the //the function realization of the view cardBayi Public Static voidLookpoker (String name,treeset<integer>ts, theHashmap<integer, string>HM) { theThe SYSTEM.OUT.PRINTLN (name + "card is:"); - for(Integer key:ts) { -String value =Hm.get (key); theSystem.out.print (Value + "")); the } the System.out.println (); the } -}
18.29_ Collection Framework (Code implementation that simulates the bucket landlord shuffling and licensing and sorts the cards)