修改后的抽奖系统
package p1;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public class choujiang {
ArrayList<Integer> values;
public ArrayList<Integer> deal(){
if(values==null){
values=new ArrayList<Integer>();
for(int i=1;i<=2000;i++){
values.add(i);
}
}
Collections.shuffle(values);
return values;
}
public void display(){
String[] player ={"一等奖","二等奖","三等奖"};
for(int i=0;i<3;i++){
System.out.print(player[i]+":");
for(int j=0;j<=i;j++){
Random r=new Random();
int number =r.nextInt(2000)+1;
System.out.print(values.get(number)+"号 ");
values.remove(number);
}
System.out.println();
}
}
public static void main(String[] args) {
choujiang c=new choujiang();
c.deal();
c.display();
}
}
期末设计