java--> Simple bucket landlord licensing process

Source: Internet
Author: User

 PackageCom.dragon.java.hwddz;Importjava.util.ArrayList;ImportJava.util.HashMap;Importjava.util.List;ImportJava.util.Map;/*1. Write a program that can give the bucket landlord three random licensing.    A: Cards can be randomly issued to three players B: print each player's card on the console. C: The cards in each player's hands are sorted in uppercase. "The suit:" ♠ "," ♥ "," ♣ "," ♦ "* idea: Create a container to store all the cards, then create three containers representing three user cards, three users take turns from the first container, * The remaining three cards for the card. The King and the King are counted in .*/ Public classTest { Public Static voidMain (String args[]) {Map<integer, string> mappoker =NewHashmap<>(); List<Integer> ListIndex =NewArraylist<>();        Poker.setpoker (Mappoker, ListIndex); Poker.washpoker (ListIndex);
     
//define userplayer[] Players=NewPlayer[3]; players[0] =NewPlayer ("Lying in the DS"); players[1] =NewPlayer ("Little Scissors"); players[2] =NewPlayer ("Stay in the name");
     //user container List
<Integer> Tzd =NewArraylist<>(); List<Integer> XJ =NewArraylist<>(); List<Integer> DLJ =NewArraylist<>(); List<Integer> DP =NewArraylist<>(); Player.getpoker (Tzd, XJ, DLJ, DP, ListIndex); //int index = player.getmaxnumber (players); //System.out.println (Players[index].getname () + "Rob the Landlord!" ");players[0].showpoker (Tzd, Mappoker); players[1].showpoker (XJ, Mappoker); players[2].showpoker (DLJ, Mappoker); //PLAYERS[INDEX].SHOWDP (DP, mappoker);System.out.println ("\ n" + "Hole Card:"); for(integer INTEGER:DP) {System.out.print (Mappoker.get (integer)+ " "); } }}

--Poker class for depositing 54 cards

 PackageCom.dragon.java.hwddz;Importjava.util.Collections;Importjava.util.List;ImportJava.util.Map; Public classPoker {Private StaticString[] Pokercolor = {"♠", "♥", "♣", "♦" }; Private StaticString[] Pokernum = {"3", "4", "5", "6", "7", "8", "9",            "Ten", "J", "Q", "K", "A", "2" };
   //Deposit 54 different cards and give each card a label
Public Static voidSetpoker (Map<integer, string>Mappoker, List<Integer>ListIndex) { intindex = 0; for(String nums:pokernum) { for(String colors:pokercolor) {string Poker=Colors.concat (nums); Mappoker.put (index, poker); Listindex.add (index); Index++; }} mappoker.put (Index,"Great King"); Listindex.add (index); Index++; Mappoker.put (Index,"Little King"?); Listindex.add (index); }
   //Shuffle
-and-wash label
Public Static voidWashpoker (list<integer>ListIndex) {collections.shuffle (ListIndex); }}

--The Player class deals with the player's licensing and display (I regret it, j,q,k,a,2 's sort is too low.) Package Com.dragon.java.hwddz;

Importjava.util.ArrayList;Importjava.util.Collections;ImportJava.util.Comparator;Importjava.util.List;ImportJava.util.Map;ImportJava.util.Random; Public classPlayer {PrivateString name; Player () {Super(); } Player (String name) {Super();  This. Name =name; }     PublicString GetName () {returnname; }     Public voidsetName (String name) { This. Name =name; }
   //Licensing process
Public Static voidGetpoker (list<integer> player1, list<integer>Player2, List<Integer> Player3, list<integer> dp, list<integer>list) { for(inti = 0; I < list.size (); i++) { if(I >= list.size ()-3) {Dp.add (List.get (i)); } Else if(i% 3 = = 1) {Player1.add (List.get (i)); } Else if(i% 3 = = 2) {Player2.add (List.get (i)); } Else if(i% 3 = = 0) {Player3.add (List.get (i)); } } }
   //Display
face
Public voidShowpoker (list<integer> List, Map<integer, string>Mappoker) {System.out.println (The "\ n" + name + "Hand is:"); List<String> Listpoker =NewArraylist<>(); for(Integer key:list) {Listpoker.add (Mappoker.get (key)); } collections.sort (Listpoker,Newmycomparator ()); for(String string:listpoker) {System.out.print (string+ " "); } } //Public void SHOWDP (list<integer> dp, Map<integer, string> mappoker) {//list<string> listpoker = new arraylist<> (); //For (Integer key:dp) {//Listpoker.add (Mappoker.get (key)); // } //Collections.sort (Listpoker, New Mycomparator ()); //For (String string:listpoker) {//System.out.print (String + ""); // } // } Public intthrowselbows () {random random=NewRandom (); intnum = Random.nextint (6) + 1; SYSTEM.OUT.PRINTLN (Name+ "Shake" + num + "dot"); returnnum; } //Please ignore the comments below ...//public static int Getmaxnumber (player[] players) {//list<integer> numbers = new arraylist<> (); //for (int i = 0; i < players.length; i++) {//Numbers.add (Players[i].throwselbows ()); // } //Collections.sort (numbers); //for (int i = 0; i < numbers.size ()-1; i++) {//if (Numbers.get (Numbers.size ()-1) = = Numbers.get (i)) {//System.out.println (Players[numbers.size ()-1].name + "and"//+ players[i].name + "Shake the same number of points"); //System.out.println ("They fought a fight!") --"+ Players[i].name +" won! "); //return i; // } // } //return Numbers.size ()-1; // }

  
//Card comparison sort--I'm bored ... Public Static classMycomparatorImplementsComparator<string>{@Override Public intCompare (String O1, String O2) {string M1= O1.substring (1, 2); String m2= O2.substring (1, 2); if(M1.equals ("1") ) {M1= "a"; } Else if(M1.equals ("J") ) {M1= "B"; } Else if(M1.equals ("Q") ) {M1= "C"; } Else if(M1.equals ("K") ) {M1= "D"; } Else if(M1.equals ("A") ) {M1= "E"; } Else if(M1.equals ("2") ) {M1= "F"; } if(M2.equals ("1") ) {m2= "a"; } Else if(M2.equals ("J") ) {m2= "B"; } Else if(M2.equals ("Q") ) {m2= "C"; } Else if(M2.equals ("K") ) {m2= "D"; } Else if(M2.equals ("A") ) {m2= "E"; } Else if(M2.equals ("2") ) {m2= "F"; } returnM1.compareto (m2); } }}

--Is there a problem with the discovery logic?

java--> Simple bucket landlord licensing process

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.