标签:
生成课表
import java.util.Random;
interface ClassType{
enum LIBERART implements ClassType{CHINESE, ENGLISH, HISTORY, GEOGRAPH}
enum SCIENCE implements ClassType{MATH, PHYSICS, CHEMISTRY, BIOLOGY}
enum MORAL implements ClassType{SPORT, MUSIC, PAINTING}
}
class Enums{
private static Random rand=new Random(47);
public static <T extends Enum<T>>T random(Class<T> ec){
return random(ec.getEnumConstants());
}
public static <T>T random(T[] values){
return values[rand.nextInt(values.length)];
}
}
enum Course{
LIBERART(ClassType.LIBERART.class),
SCIENCE(ClassType.SCIENCE.class),
MORAL(ClassType.MORAL.class);
private ClassType[] values;
private Course(Class<? extends ClassType>kind){
values=kind.getEnumConstants();
}
public ClassType randomSelection(){
return Enums.random(values);
}
}
public class ClassTable {
public static void main(String[] args) {
for(int i=1;i<6;i++){
System.out.println("星期"+i+":");
for(Course course:Course.values()){
ClassType t=course.randomSelection();
System.out.println(t);
}
}
}
}
标签:
原文地址:http://www.cnblogs.com/fly-in-the-sky/p/5090391.html