简单的35选7彩票系统

实例需求:
用户登录彩票系统de时候需要用户输入自己的身份证号和要选择的7个彩票号码,然后系统给出购买彩票的时间以及个人信息,随后随机产生彩票号码,最后判断是否中奖以及中奖金额。
实例化一个彩票类:
package CaiPiao;

public class LotteryBean {

private String id;
private int [] buyno;
private String buydate;
private  int[] winno;
private int wonmoney;

// 实例化一个对象来保存彩票信息:

public String getId() {
    return id;
}

public void setId(String id) {
    this.id = id;
}

public int[] getBuyno() {
    return buyno;
}

public void setBuyno(int[] buynos) {
    this.buyno = buynos;
}

public String getBuydate() {
    return buydate;
}

public void setBuydate(String buydate) {
    this.buydate = buydate;
}

public int[] getWinno() {
    return winno;
}

public void setWinno(int[] winno) {
    this.winno = winno;
}

public int getWonmoney() {
    return wonmoney;
}

public void setWonmoney(int wonmoney) {
    this.wonmoney = wonmoney;
}

}
一个测试彩票类:
package CaiPiao;

import java.text.SimpleDateFormat;
import java.util.Scanner;

public class LotteryBeanMethod {
static int sum = 0;
static int[] no = new int[7];
public static LotteryBean mylottery = new LotteryBean();

public static void main(String[] args) {
    buyLottery();
    getWinno();
    getWinMoney();
}

public static void buyLottery() {
    System.out.println("------------购买彩票--------------");
    Scanner sc = new Scanner(System.in);
    System.out.println("请输入身份证号 :   ");
    String id = sc.next();
    System.out.println("购买号码:(输入(1-35)的7个数字以逗号隔开)");
    String s2 = sc.next();
    String[] buynos = s2.split(",");
    // 把String类型的数组转换成int 类型的数组
    System.out.println("你购买的彩票信息为:");
    for (int i = 0; i < buynos.length; i++) {
        no[i] = Integer.parseInt(buynos[i]);
        System.out.print(no[i] + " ");
    }
    System.out.println();

    // 格式化当前日期
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String buydate = sdf.format(new java.util.Date());
    System.out.println("购买成功!购买日期为:" + buydate);
    mylottery.setId(id);
    mylottery.setBuyno(no);
    mylottery.setBuydate(buydate);

}

public static void getWinno() {
    System.out.println("------------彩票开奖--------------");
    int[] s = new int[7];
    for (int i = 0; i < 7; i++) {
        int a = (int) (Math.random() * 35) + 1;
        s[i] = a;
        for (int j = 1; j < i; j++) {
            while (s[i] == s[j]) {
                i--;
            }
        }
    }
    // 输出产生的随机数
    System.out.println("开奖号码:");
    System.out.println();
    mylottery.setWinno(s);

    for (int n = 0; n < 7; n++) {
        System.out.print(mylottery.getWinno()[n] + " ");
    }
    int count = 0;
    for (int n = 0; n < 7; n++) {
        for (int m = 0; m < 7; m++) {
            if (mylottery.getWinno()[n] == no[m]) {
                count++;
            }
        }
        sum = count;
    }
    System.out.println();
}

// 奖金
public static void getWinMoney() {
    System.out.println("--------兑奖信息--------");
    System.out.println("中奖的个数:" + sum);
    if (sum == 2) {
        System.out.println("中奖金额:" + 5 + "元");
    } else if (sum == 3) {
        System.out.println("中奖金额:" + 10 + "元");
    } else if (sum == 4) {
        System.out.println("中奖金额:" + 20 + "元");
    } else if (sum == 5) {
        System.out.println("中奖金额:" + 40 + "元");
    } else if (sum == 6) {
        System.out.println("中奖金额:" + 100 + "元");
    } else if (sum == 7) {
        System.out.println("中奖金额:" + 500 + "元");
    } else {
        System.out.println("没中奖");
    }

}

}

这个只是一个简单的系统,不足必然存在欢迎指正。

你可能感兴趣的:(java)