导航:首页 > 编程语言 > java实现抽奖

java实现抽奖

发布时间:2021-12-08 18:27:13

Ⅰ 求java实现转盘转动功能,抽奖,坐等

转盘转动就是图片,定义一个随机数random;
if(random==1){
画中奖的图片
}else{
画不中奖的图片}

Ⅱ 用java怎么实现控制中奖率

可以做到!用 Random 得到随机的数,再根据你的登陆人的身份 控制随机的次数是多少!
例如:
1 - 20 为中奖, 普通就随机出 10000个数。会员的话就随机100个数就好了!

Ⅲ 用java写一个抽奖程序

这一百个随机数给个范围 random(范围),再分批获取呗 ,获取到的数判断在list里存在不,存在就重新获取,不存在就添加到list中去

Ⅳ 用java做一个抽奖的代码

要在cmd下运行啊 我想你安装JDK没?

import java.util.*;
class Test{
private int maxSize=0;
private int selectSize=0;
private List<Integer> list=new ArrayList<Integer>();
private int[] one=new int[7];
public Test(int maxSize,int selectSize){
this.maxSize=maxSize;
this.selectSize=selectSize;
one=new int[selectSize];
for(int i=1;i<=maxSize;i++)
list.add(Integer.valueOf(i));
}

public void open(){
List<Integer> temp=new ArrayList<Integer>();
temp.addAll(list);
int[] p=new int[selectSize];
int tag=0;
for(int i=0;i<selectSize;i++){
tag=(int)(Math.random()*555555%temp.size());
p[i]=(Integer)temp.get(tag).intValue();
temp.remove(tag);
}
one=p;

}
public void paixu(){
int temp=0;
for(int i=0;i<selectSize;i++){
for(int j=0;j<selectSize-1;j++){
if(one[j]>one[j+1]) {temp=one[j];one[j]=one[j+1];one[j+1]=temp;}
}
}
}

public void printOpen(){
open();
paixu();
for(int i=0;i<one.length;i++)
System.out.print(one[i]+" ");
System.out.println();
}
static public void main(String[] str){
Test t=new Test(33,6); //彩票类型:33选6
for(int i=0;i<10;i++) //开10次奖
t.printOpen();

}
}

Ⅳ 使用java语言编写一个抽奖系统

packagech07;

importjavax.swing.*;

publicclassTest2{


publicstaticvoidmain(String[]args){
Stringoutput="";

output+="恭喜第"+(1+(int)(Math.random()*100))+"号中了一等奖";
output+=" 恭喜第"+(1+(int)(Math.random()*100))+"号"+(int)(1+(Math.random()*100))+"号"+"中了二等奖";
for(inti=0;i<3;i++){
output+=" 恭喜第"+(1+(int)(Math.random()*100))+"号中了三等奖";
}
JOptionPane.showMessageDialog(null,output);
}

}

程序运行结版果截图

中奖的人权是随机的!

Ⅵ 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 =custNo/100%10;
while(i==1){
if(custNo>=1000&&custNo<=9999){
break;
}
else{
System.out.println("\n会员号码输入有误,请重新输入:");
custNo=input.nextInt();
continue;
}
}

if(==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技术实现幸运抽奖活动系统

import java.util.Scanner;
public class LuckyNumber {
/**
* 幸运抽奖
*/
public static
void main(String[] args) {
String answer
= "y"; // 标识是否继续
String
userName = ""; // 用户名
String
password = ""; // 密码
int cardNumber
= 0; // 卡号
boolean
isRegister = false; // 标识是否注册
boolean
isLogin = false; // 标识是否登录
int max =
9999;
int min =
1000;
Scanner input
= new Scanner(System.in);
do {
System.out.println("*****欢迎进入奖客富翁系统*****");
System.out.println("\t1.注册");
System.out.println("\t2.登录");
System.out.println("\t3.抽奖");
System.out.println("***************************");
System.out.print("请选择菜单:");
int choice =
input.nextInt();
switch
(choice) {
case 1:
System.out.println("[奖客富翁系统
> 注册]");
System.out.println("请填写个人注册信息:");
System.out.print("用户名:");
userName =
input.next();
System.out.print("密码:");
password =
input.next();
//
获取4位随机数作为卡号
cardNumber =
(int)(Math.random()*(max-min))+min;
System.out.println("\n注册成功,请记好您的会员卡号");
System.out.println("用户名\t密码\t会员卡号");
System.out.println(userName
+ "\t" + password + "\t" + cardNumber);
isRegister =
true; // 注册成功,标志位设置为true
break;
case 2:
System.out.println("[奖客富翁系统
> 登录]");
if
(isRegister) { // 判断是否注册
//
3次输入机会
for (int i
= 1; i <= 3; i++) {
System.out.print("请输入用户名:");
String
inputName = input.next();
System.out.print("请输入密码:");
String
inputPassword = input.next();
if
(userName.equals(inputName) && password.equals(inputPassword)) {
System.out.println("\n欢迎您:"
+ userName);
isLogin =
true; // 登录成功,标志位设置为true
break;
} else if
(i < 3) {
System.out.println("用户名或密码错误,还有"
+ (3 - i) + "次机会!");
} else
{
System.out.println("您3次均输入错误!");
}
}
} else
{
System.out.println("请先注册,再登录!");
}
break;
case 3:
System.out.println("[奖客富翁系统
> 抽奖]");
if
(!isLogin) { // 判断是否登录
System.out.println("请先登录,再抽奖!");
} else
{
//生成5个4位随机数字,并保存在数组中
int[]
luckynums = new int[5];
for(int i
= 0; i < luckynums.length; i++){
luckynums[i] =
(int)(Math.random()*(max-min))+min;
}
System.out.print("请输入您的卡号:");
int
yourcard = input.nextInt();
int
i;
System.out.print("\n本日的幸运数字为:");
for (i = 0;
i < luckynums.length; i++) {
System.out.print(luckynums[i]
+ " ");\
}
for (i = 0;
i < luckynums.length; i++) {
if
(luckynums[i] == yourcard) {
System.out.println("\n恭喜!您是本日的幸运会员!");
break;
}
}

if (i ==
luckynums.length) {
System.out.println("\n抱歉!您不是本日的幸运会员!");
}
}
break;
default:
System.out.println("[您的输入有误!]");
break;
}
System.out.print("继续吗?(y/n):");
answer =
input.next();
System.out.println("");
} while
("y".equals(answer));
if
("n".equals(answer)) {
System.out.println("系统退出,谢谢使用!");

}

}
}

Ⅷ 做一个JAVA的抽奖系统

用随机的办法 来 作为抽奖结果 是误人的。。。。
理想办法是生成抽奖池

然后以随机数的办法生成数据进入抽奖池中抽取奖品

并且加入判断语句来过滤已经抽取出来的奖品 一直到奖池为空

Ⅸ 关于java抽奖代码

if (b==1);{
System.out.println("您抽到的是一等奖");)
}
好像是少了{}
程序从上往下读的 System.out.println("您抽到的是一等奖"); 不在if的里面。

Ⅹ 以JAVA为平台实现摇号抽奖

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;

import java.util.*;

import java.io.FileReader;
import java.io.File;

// This example demonstrates the use of JButton, JTextField
// and JLabel.
public class LunarPhases implements ActionListener {
final static int NUM_IMAGES = 1000;

final static int START_INDEX = 0;

int REAL_NUM_IMAGES = 0;

ImageIcon[] images = new ImageIcon[NUM_IMAGES];

String[] imageNames = new String[NUM_IMAGES];

JPanel mainPanel, selectPanel, displayPanel, resultPanel;

JButton phaseChoice = null;

JLabel phaseIconLabel = null, phaseResult = null;

// Constructor
public LunarPhases() {
// Create the phase selection and display panels.
selectPanel = new JPanel();
displayPanel = new JPanel();
resultPanel = new JPanel();

// Add various widgets to the sub panels.
addWidgets();

// Create the main panel to contain the two sub panels.
mainPanel = new JPanel();
mainPanel.setLayout(new GridLayout(1, 3, 5, 5));
mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

// Add the select and display panels to the main panel.
mainPanel.add(selectPanel);
mainPanel.add(displayPanel);
mainPanel.add(resultPanel);
}

// Create and the widgets to select and display the phases of the moon.
private void addWidgets() {
// Get the images and put them into an array of ImageIcon.
File dir = new File("C:\\Program Files\\JavaSoft\\JDK1.3.1\\bin\\images");
File[] files = dir.listFiles();
String imageName = null;
String temp = null;
int j = 0;
for (int i = 0; i < files.length; i++) {
if (!files[i].isDirectory()) {
imageName = "images/" + files[i].getName();
}
temp = imageName.substring(imageName.lastIndexOf(".") + 1, imageName.length());
if(!temp.equals("gif"))
{
continue;
}
URL iconURL = ClassLoader.getSystemResource(imageName);
ImageIcon icon = new ImageIcon(iconURL);
images[j] = icon;
imageNames[j] = imageName.substring(7,imageName.lastIndexOf("."));
j++;
}
REAL_NUM_IMAGES = j;

// Create label for displaying moon phase images and put a border around
// it.
phaseIconLabel = new JLabel();
phaseIconLabel.setHorizontalAlignment(JLabel.CENTER);
phaseIconLabel.setVerticalAlignment(JLabel.CENTER);
phaseIconLabel.setVerticalTextPosition(JLabel.CENTER);
phaseIconLabel.setHorizontalTextPosition(JLabel.CENTER);
phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLoweredBevelBorder(), BorderFactory
.createEmptyBorder(5, 5, 5, 5)));

phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(0, 0, 10, 0), phaseIconLabel
.getBorder()));

phaseResult = new JLabel();

// Create combo box with lunar phase choices.
phaseChoice = new JButton("开始/停止");

// Display the first image.
phaseIconLabel.setIcon(images[START_INDEX]);
phaseIconLabel.setText("");

// Add border around the select panel.
selectPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createTitledBorder("Select Phase"), BorderFactory
.createEmptyBorder(5, 5, 5, 5)));

resultPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createTitledBorder("Result Phase"), BorderFactory
.createEmptyBorder(5, 5, 5, 5)));

// Add border around the display panel.
displayPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createTitledBorder("Display Phase"), BorderFactory
.createEmptyBorder(5, 5, 5, 5)));

// Add moon phases combo box to select panel and image label to
// displayPanel.
selectPanel.setLayout(new GridLayout(3,3));//这里原来是selectPanel.add(phaseChoice);
// displayPanel.add(phaseIconLabel);
// resultPanel.add(phaseResult);

selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
selectPanel.add(phaseChoice);
selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
selectPanel.add(new JLabel());
resultPanel.setLayout(new BorderLayout());
displayPanel.add(phaseIconLabel);
resultPanel.add(phaseResult);

// Listen to events from combo box.
phaseChoice.addActionListener(this);
}

boolean run = false;
// Implementation of ActionListener interface.
public void actionPerformed(ActionEvent event) {
if(run){
run = false;
}
else{
run = true;
new Thread(){
public void run(){
while(run){
int a =(int)( Math.random()*REAL_NUM_IMAGES);
phaseIconLabel.setIcon(images[a]);
phaseResult.setText(imageNames[a]);
try{
Thread.sleep(100);
}
catch(Exception e){}
}
}
}.start();
}
}

// main method
public static void main(String[] args) {
// create a new instance of LunarPhases
LunarPhases phases = new LunarPhases();

// Create a frame and container for the panels.
JFrame lunarPhasesFrame = new JFrame("Lunar Phases");

// Set the look and feel.
try {
UIManager.setLookAndFeel(UIManager
.());
} catch (Exception e) {
}

lunarPhasesFrame.setContentPane(phases.mainPanel);

// Exit when the window is closed.
lunarPhasesFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Show the converter.
lunarPhasesFrame.pack();
lunarPhasesFrame.setVisible(true);
}
}

阅读全文

与java实现抽奖相关的资料

热点内容
iphone来电壁纸 浏览:40
删除文件夹找不到指定路径怎么办 浏览:487
原力大数据招聘 浏览:479
数据线圆头什么意思 浏览:768
协和app怎么取号 浏览:664
c坐标转换代码 浏览:707
唐筛数据为什么能看出男女 浏览:44
快手java 浏览:835
qq分享的文件在哪里 浏览:226
爱念电影 浏览:656
97不用下载播放器的 浏览:649
在线观看0855影视 浏览:489
女主叫向晚棠的小说 浏览:841
uglifyjs使用 浏览:328
西班牙最大寸度电影 浏览:641
孤寂之狼txt无删笔趣阁 浏览:895
微程序微指令微操作机器指令 浏览:370
百合小说下载 浏览:477
iphone7怎么新建文件夹 浏览:339
如何用复印机打印u盘文件 浏览:377

友情链接