import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Random;
/*
* 设计一个抽奖功能
* 1.中奖的概率
* 2.中奖项目
* 3.人员匹配
* 4.已中奖人员不能再中奖
*/
public class DemoRan {
//放置已中奖人员编号
static ArrayList<Integer> employD = new ArrayList<>();
public static void main(String[] args) {
LinkedHashMap<Integer, String> draw = new LinkedHashMap<>();
draw.put(1, "一等奖:苹果手机");
draw.put(2, "二等奖:平板ipad");
draw.put(3, "三等奖:华为智能手表");
draw.put(4, "四等奖:蓝牙耳机");
draw.put(5, "未中奖");
ArrayList<Integer> employ = new ArrayList<>();
for(int j = 1;j < 1000;j++){
employ.add(j);
}
draw(employ,"一等奖 ",3);
System.out.println();
draw(employ,"二等奖",3);
}
//抽出中奖号码
public static ArrayList<Integer> draw(ArrayList<Integer> employ,String num,int b) {
// num代表奖项 b代表中奖人数
Collections.shuffle(employ); //打乱人员编号
System.out.print(num+"的中奖编号");
for(int i=0;i< b;i++){
while(true) {
if(!employD.contains(employ.get(i))) {
employD.add(employ.get(i));
System.out.print(" "+employ.get(i)+" ");
break;
}else {
i++;
}
}
}
System.out.println();
return employD;
}
}