Java--> Licensing Process modified version

Source: Internet
Author: User

And this time it's going to be a bit hard to package ...

 PackageCom.xm.ddz;//properties of each card Public classCard {PrivateString Flowercolor; PrivateString number; Private intLevel ;  Public intCompareTo (Card c) {return  This. Level-C.getlevel (); }     PublicString Getflowercolor () {returnFlowercolor; }     Public voidSetflowercolor (String flowercolor) { This. Flowercolor =Flowercolor; }     PublicString GetNumber () {returnNumber ; }     Public voidSetnumber (String number) { This. Number =Number ; }     Public intGetlevel () {returnLevel ; }     Public voidSetLevel (intLevel ) {         This. Level =Level ; } @Override PublicString toString () {return"Card [flowercolor=" + Flowercolor + ", number=" + number + ", level=" + level + "]"; }     PublicCard (String Flowercolor, string number,intLevel ) {         This. Flowercolor =Flowercolor;  This. Number =Number ;  This. Level =Level ; }     PublicCard () {}}

--The Poker class still stores 54 cards--but each card has a level value to determine its order in poker

 PackageCom.xm.ddz;Importjava.util.ArrayList;Importjava.util.List; Public classPoker {PrivateString[] flowercolors = {"♠", "♥", "♣", "♦" }; Privatestring[] numbers = {"3", "4", "5", "6", "7", "8", "9", "Ten", "J", "Q", "K", "A", "2" }; PrivateString[] boss = {"Xiao Wang", "King" }; Privatelist<card> list =NewArraylist<>();  PublicList<card>getList () {returnlist; }     PublicPoker () { for(inti = 0; i < flowercolors.length; i++) {             for(intj = 0; J < Numbers.length; J + +) {List.add (NewCard (Flowercolors[i], Numbers[j], j)); }} list.add (NewCard ("Black", Boss[0], 99)); List.add (NewCard ("Red", boss[1], 100)); }     Public voidPrintinfo () { for(Card c:list) {System.out.println (c.tostring ()); }    }}

--The Player class is used to receive cards on the hand

 PackageCom.xm.ddz;Importjava.util.ArrayList;Importjava.util.List; Public classPlayer {PrivateString name; Privatelist<card> list =NewArraylist<>();  PublicPlayer (String name) {Super();  This. Name =name; }    /*** Player Receives card * *@paramC*/     Public voidAddcard (Card c) {List.add (c); }    /*** Ascending order*/     Public void() { for(inti = 0; I < List.size ()-1; i++) {             for(intj = 1; J < List.size ()-I; J + +) {                if(List.get (j-1). CompareTo (List.get (j)) > 0) {                    FinalCard C =List.get (j); List.set (J, List.get (J-1)); List.set (J-1, c); } }} @Override PublicString toString () {by (); StringBuilder SB=NewStringBuilder (); Sb.append ("\n******************" + name + "*********************\n");  for(inti = 0; I < list.size (); i++) {sb.append (List.get (i). toString ()); Sb.append ("\ n"); } sb.append ("***************************************"); returnsb.tostring (); }}

--Dealpoker class performs a licensing operation

 PackageCom.xm.ddz;Importjava.util.List;ImportJava.util.Random; Public classDealpoker {Privateplayer[] players; PrivatePoker p;  PublicDealpoker (player[] players, Poker p) { This. Players =players;  This. P =p; }    /*** Licensing*/     Public voidDispatchcard () {Finallist<card> list =p.getlist (); Random R=NewRandom (); inti = 0;  while(List.size () > 0) {            intindex = R.nextint (List.size ());//random int value from 0-list.size () (not including list.size ())players[i++%Players.length].addcard (List.remove (index)); }         for(intj = 0; J < Players.length; J + +) {System.out.println (players[j].tostring ()); }    }}

--Test class

 Package Com.xm.ddz;  Public class Test {    publicstaticvoid  main (string[] args) {        new Poker ();         New New New Player ("Lao Wang")};         New Dealpoker (players, poker);        Dealpoker.dispatchcard ();    }}

-It looks much better than the last time, but it still doesn't make it to the landlord.

Java--> Licensing Process modified version

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.