Java -- & gt; simple landlords licensing process, java -- landlords

Source: Internet
Author: User

Java --> simple landlords licensing process, java -- landlords

Package com. dragon. java. hwddz; import java. util. arrayList; import java. util. hashMap; import java. util. list; import java. util. map;/* 1. write a program for random licensing of three landlords. A: The card can be randomly sent to three players. B: print each player's card on the console. C: sort the cards in each player's hands in uppercase. ''' Card color :"♠","♥","♣","♦"* Idea: Create a container to store all the cards, and then create three containers to indicate the cards of the three users. The three users take turns to take the cards from the first container, * The remaining three cards are the cards. Calculate kingdom and kingdom as well **/public class Test {public static void main (String args []) {Map <Integer, String> mapPoker = new HashMap <> (); list <Integer> listIndex = new ArrayList <> (); Poker. setPoker (mapPoker, listIndex); Poker. extends poker (listIndex );
// Define the user Player [] players = new Player [3]; players [0] = new Player ("Lie down "); players [1] = new Player (""); players [2] = new Player (" ");
// User container List <Integer> tzd = new ArrayList <> (); List <Integer> xj = new ArrayList <> (); list <Integer> dlj = new ArrayList <> (); List <Integer> dp = new ArrayList <> (); Player. getPoker (tzd, xj, dlj, dp, listIndex); // int index = Player. getMaxNumber (players); // System. out. println (players [index]. getName () + "grabbed 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" + "card:"); for (Integer integer: dp) {System. out. print (mapPoker. get (integer) + "");}}}

--> Poker class is used to store 54 cards

Package com. dragon. java. hwddz; import java. util. collections; import java. util. list; import java. util. map; public class Poker {private static String [] pokerColor = {"♠","♥","♣","♦"}; Private static String [] pokerNum = {" 3 "," 4 "," 5 "," 6 "," 7 "," 8 "," 9 ", "10", "J", "Q", "K", "A", "2 "};
// Store 54 cards and give each card a public static void setPoker (Map <Integer, String> mapPoker, List <Integer> listIndex) {int index = 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, ""); listIndex. add (index); index ++; mapPoker. put (index, "Small☟Wang "); listIndex. add (index );}
// Shuffling --> indicates the public static void sort poker (List <Integer> listIndex) {Collections. shuffle (listIndex );}}

--> The Player class deals with players and displays the players. (After writing, I regret it. The order of J, Q, K, A, and 2 is too low .. package com. dragon. java. hwddz;

Import java. util. arrayList; import java. util. collections; import java. util. comparator; import java. util. list; import java. util. map; import java. util. random; public class Player {private String name; Player () {super () ;}player (String name) {super (); this. name = name;} public String getName () {return name;} public void setName (String name) {this. name = name ;}
// Public static void getPoker (List <Integer> player1, List <Integer> player2, List <Integer> player3, List <Integer> dp, List <Integer> list) {for (int I = 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 ));}}}
// Public void showPoker (List <Integer> list, Map <Integer, String> mapPoker) {System. out. println ("\ n" + name + ":"); List <String> listPoker = new ArrayList <> (); for (Integer key: list) {listPoker. add (mapPoker. get (key);} Collections. sort (listPoker, new MyComparator (); for (String string: listPoker) {System. out. print (string + "") ;}}// public void showDp (List <Integer> dp, Map <Integ Er, 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 int throwsElbows () {Random random = new Random (); int num = random. nextInt (6) + 1; System. out. println (name + "Shake" + n Um + "point"); return num;} // ignore the following comment... // 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 (playe Rs [numbers. size ()-1]. name + "and" // + players [I]. name + "the same number of shake points"); // System. out. println ("they got a fight! --> "+ Players [I]. name +" wins! "); // Return I; //} // return numbers. size ()-1 ;//}

  
// Sort cards in a more ordered manner --> it's annoying to read them...Public static class MyComparator implements Comparator <String >{@ Override public int compare (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 ";} return m1.compareTo (m2 );}}}

--> Is there a problem with the logic found after writing...

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.