大家还记得《石灰吟》的作者于谦吗?他是被明英宗朱祁镇杀死的,对,就是在土木堡之变中被瓦刺俘虏的皇帝,被俘虏后他弟弟朱祁钰当上了皇帝,就是明景帝,后来朱祁镇被救回来后,竟然同时出现了两个皇帝。
public class Emperor {
private static int maxNumOfEmperor = 2; // 最多有两个皇帝
private static ArrayList emperorInfoList = new ArrayList(maxNumOfEmperor);// 皇帝的名字
private static ArrayList emperorList = new ArrayList(maxNumOfEmperor);// 装皇帝的列表
private static int curEmperor = 0;// 正在被人尊称的皇帝
static {
for (int i = 0; i < maxNumOfEmperor; i++) {
emperorList.add(new Emperor("皇" + (i + 1) + "帝"));
}
}
private Emperor() {
}
private Emperor(String info) {
emperorInfoList.add(info);
}
public static Emperor getInstance() {
Random r = new Random();
curEmperor = r.nextInt(maxNumOfEmperor);
return (Emperor) emperorList.get(curEmperor);
}
public static void emperorInfo(){
System.out.println(emperorInfoList.get(curEmperor));
}
}
大臣悲惨了,两个皇帝,怎么拜啊,不管了,只要是个皇帝就成。
public class Minister {
public static void main(String[] args) {
int minister = 10;// 10个大臣
for (int i = 0; i < minister; i++) {
Emperor emperor = Emperor.getInstance();
System.out.println("第" + (i + 1) + "个大臣参拜的是:");
emperor.emperorInfo();
}
}
}