首页 > 编程知识 正文

java写一个年会抽奖系统(java实现抽奖)

时间:2023-12-13 14:15:35 阅读:315153 作者:EBVZ

本文目录一览:

做一个JAVA的抽奖系统

这么点分,我不能给你编

我给你说思路吧

当用户点击抽奖

你就自动生成一个0~10000的随机数(大点有代表性)

然后判断这个数,如果能被10整除,就视为中一等奖

如果能被5整除

视为二等奖

java做抽奖系统

import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.util.*;public class ChooseAward extends JFrame{ /** * */ //系统自动生成 private static final long serialVersionUID = 7510608124693852355L; JButton b_start = new JButton("开始"); JButton b_stop = new JButton("停止"); JPanel p_north=new JPanel(); JPanel p_center=new JPanel(); JPanel p_south=new JPanel(); //菜单栏 JMenuBar menubar=new JMenuBar(); //菜单项 JMenu fileMenu=new JMenu("文件"); JMenu setMenu=new JMenu("设置"); JMenu aboutMenu=new JMenu("关于"); /* * 菜单子项 */ private JMenuItem[] filem={new JMenuItem("选择文件"),new JMenuItem("另存为.."), new JMenuItem("保存"),new JMenuItem("退出") }; JTextField t_identNumber = new JTextField(); // 身份证号的文本域 Vector v_identNumber = new Vector(); // 存放读取出来的身份证的号码 Vector v_name = new Vector(); // 存放读取出来的人的姓名 Vector v_printident = new Vector(); // 存放中奖人的身份证号码 JLabel l_information = new JLabel(); JLabel l_identNumber = new JLabel(); JLabel l_sysinformation = new JLabel("系统信息:"); JFileChooser filechooser = new JFileChooser(); // 文件选择器 //选择随机数的线成 public ChooseThread awardThread = null; int chooseTime = 0; // 按下停止按钮的次数,也就是抽奖的次数 public ChooseAward() { super("小型抽奖系统"); t_identNumber.setEditable(false); /* * 1.4以后的JDK可以不用Container */ Container contentPane = getContentPane(); //BorderLayout布局管理器,东,南,西,北 contentPane.setLayout(new BorderLayout()); /* * 给几个按钮和子菜单添加监听器 */ filem[0].addActionListener(new ActionListener() { // 注册加载事件的监听器 public void actionPerformed(ActionEvent e) { b_loadident_ActionPerformed; } }); b_start.addActionListener(new ActionListener() { // 注册开始事件的监听器 public void actionPerformed(ActionEvent e) { b_start_ActionPerformed; } }); b_stop.addActionListener(new ActionListener() {// 注册停止事件的监听器 public void actionPerformed(ActionEvent e) { b_stop_ActionPerformed; } }); filem[2].addActionListener(new ActionListener() {// 注册打印事件的监听器 public void actionPerformed(ActionEvent e) { b_printaward_ActionPerformed; } }); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); //将菜单子项加入菜单中 for(int i=0;ifilem.length;i++) { fileMenu.add(filem[i]); //加入分隔线,为了美观 fileMenu.addSeparator(); } //将菜单条加入frame中 menubar.add(fileMenu); menubar.add(setMenu); menubar.add(aboutMenu); setJMenuBar(menubar); /*将p_north设计为一个状态栏,显示一些操作过程中的信息 * 创建一个左对齐方式的流布局 */ p_south.setLayout(new FlowLayout(FlowLayout.LEFT)); l_information.setForeground(Color.blue); p_south.add(l_sysinformation); p_south.add(l_information); contentPane.add(p_south,BorderLayout.SOUTH);

java抽奖程序

我给你个比较简单的,,但是需要按照你的要求进行稍微的修改。。然后在main方法中去执行就可以了:

public class GoodLuck {

int custNo;

int i=1;

String answer;

String awardName;

public void LuckNo(){

Scanner input=new Scanner(System.in);

System.out.println("n我行我素购物管理系统 幸运抽奖n");

do{

// 需要的话请把随机数调整成你想要的范围(我这个是为了测试方便写的1

(~3的随机数,根据你的需要把下面的3换成你想要的数字就行了)

int num=(int)(Math.random()*3+1);

System.out.print("请输入会员卡号(4位整数):");

custNo=input.nextInt();

//百位数与随机数相同的为幸运者

int bai=custNo/100%10;

while(i==1){

if(custNo=1000custNo=9999){

break;

}

else{

System.out.println("n会员号码输入有误,请重新输入:");

custNo=input.nextInt();

continue;

}

}

if(bai==num){

showAward();

System.out.print("n卡号:"+custNo+"是幸运客户,获得"+awardName);

}else{

System.out.print("n卡号:"+custNo+"t谢谢您的支持!");

}

System.out.println("n是否继续(y/n)");

answer=input.next();

while(i==1){

if(answer.equals("y")||answer.equals("n")){

break;

}else{

System.out.print("输入有误!请重新输入:");

answer=input.next();

continue;

}

}

}while(!answer.equals("n"));

}

public void showAward(){

int num=(int)(Math.random()*3+1);

if(num==1){

awardName="Mp3";

}

else if(num==2){

awardName="美的微波炉";

}

else{

awardName="美的电饭锅";

}

}

java写一个年会抽奖系统,参与抽奖人员名单怎么存放呢?数组,集合,文件。怎么弄?

编号加名词 放集合比较好 建个用户类 最好能联网 这样就可是实时控制抽到的人 在数据库中建个字段 设置默认值 加个触发监听 一旦有查询 返回值并把数据变回默认值 在程序中建个变量默认0 开始时新建线程联网读取数据库字段 读到后赋值给程序中的变量,点结束是判断程序中的变量值 如果是默认值 随机生成结果 如果不是 生成指定结果 这样你就可以建个网页 通过手机实时控制抽奖结果了

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。