In this case? Yes! Is there a big noise? Yes, yes, indeed, it appeared in the Ming Dynasty. During the period of the Three Kingdoms, it was not counted, not counted. They were called emperors, and each had its own territory and the country account was different. Everybody else
Do you remember the poem liyin? Who is the author? Yu Qian, who killed him? Zhu qizhen, mingyingzong, yes, that is, the emperor who was stabbed and captured in the change of the Civil fort. After being captured, his younger brother Zhu qiyu became
The Emperor is the Emperor Ming jingdi. It is estimated that after the Emperor became an emperor, he was crazy. He forgot to cut his elder brother Zhu qizhen into an emperor. In the history of China, there were two Emperors in this period, you said how depressing the minister was during this period, two emperors.
Two objects of spiritual attachment.
In our design model, this scenario is called the multi-sample mode with an upper limit (the multi-sample mode with no upper limit is too easy, and there is no difference between it and the new object directly, so we will not discuss it). How can we achieve this, take a look at my tricks and look at the class diagram first:
Then, let's look at the program and define the two emperors first:
1 package COM. iadmob. multition; 2 3 Import Java. util. arraylist; 4 Import Java. util. random; 5 6/** 7 * @ author http://www.cnblogs.com/initial-road/ 8 * China's history is generally a dynasty an emperor, there are two emperors, it is inevitable to PK out of a valley. 9 * the problem arises: What if two emperors appear in China at one time? For example, after the change of the Ming Dynasty Civil fort, 10 x Emperor Ming was taken prisoner and Emperor Ming Jing was on the throne. However, after Emperor Ming Jing became an emperor, he forgot to turn his old brother Ming Yingzong into an emperor, 11 * in the past month or so, there were two Emperors in China! 12 */13 public class Emperor {14 Private Static int maxnumofemperor = 2; // up to two emperors can have 15 Private Static arraylist <string> emperorinfolist = new arraylist <string> (maxnumofemperor ); // name of the Emperor 16 Private Static arraylist <Emperor> emperorlist = new arraylist <Emperor> (maxnumofemperor); // name of the Emperor 17 Private Static int countnumofemperor = 0; // The emperor who is being honored is 18 19 // so many emperors are not allowed to elect an emperor (new emperor) 20 private Emperor () {21 // secular and moral constraints on you, the purpose is not to let you generate the second emperor 22} 23 24 private Emperor (string info) {25 emperorinfolist. add (Info); 26} 27 28 // generate two emperors first 29 static {30 // generate all Emperors 31 for (INT I = 0; I <maxnumofemperor; I ++) {32 emperorlist. add (new emperor ("" + (I + 1) + ""); 33} 34} 35 36 public static Emperor getinstance () {37 random = new random (); 38 countnumofemperor = random. nextint (maxnumofemperor); // randomly pulls an emperor. As long as it is a spiritual leader, it becomes 39 return (Emperor) emperorlist. get (countnumofemperor); 40} 41 42 // What is the name of the Emperor? 43 public static void emperorinfo () {44 system. out. println (emperorinfolist. get (countnumofemperor); 45} 46}
Then the Minister is miserable. Two Emperors and two elders worship me. No matter what it is, as long as they are Emperors, they will become:
1 package COM. iadmob. multition; 2 3/** 4 * @ author http://www.cnblogs.com/initial-road/ 5 * Ministers miserable, an emperor can not wait, now there are two emperors 6 * TMD, no matter, find an emperor and bow your head. Please be an emperor! 7 */8 Public Class Minister {9 10 public static void main (string [] ARGs) {11 int ministernum = 10; // 10 Ministers 12 for (INT I = 0; I <ministernum; I ++) {13 Emperor = emperor. getinstance (); 14 system. out. print ("no" + (I + 1) + "The Ministers visited:"); 15 emperor. emperorinfo (); 16} 17} 18 19}
Then you may be disdainted: Some ministers have the backbone to worship only one real God. What do you do? Getinstance (PARAM) can be processed!
Multisample mode [multition pattern]