import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Scanner;
public class Lottery {
public static LotteryBean mylottery = new LotteryBean();
public static void main(String[] args) {
buyLottery();
getWinno();
getWinMoney();
}
public static void getWinMoney() {
HashSet<Integer> hs = new HashSet<>();
hs.addAll(mylottery.getBuyno());
hs.addAll(mylottery.getWinno());
int temp = 14 - hs.size();
switch (temp) {
case 7:
mylottery.setWinmoney(5000000);
break;
case 6:
mylottery.setWinmoney(1000000);
break;
case 5:
mylottery.setWinmoney(3000);
break;
case 4:
mylottery.setWinmoney(200);
break;
case 3:
mylottery.setWinmoney(10);
break;
case 2:
mylottery.setWinmoney(5);
break;
default:
mylottery.setWinmoney(0);
break;
}
System.out.println("----------兑奖信息------------");
System.out.println("中奖个数:" + temp);
System.out.println("中奖金额:" + mylottery.getWinmoney() + "元");
}
public static void getWinno() {
int number;
HashSet<Integer> hs1 = new HashSet<>();
System.out.println("\n---------彩票开奖------------");
while (hs1.size() < 7) {
number = 1 + (int) (Math.random() * 35);
hs1.add(number);
}
System.out.println(hs1);
mylottery.setWinno(hs1);
}
public static void buyLottery() {
Scanner input = new Scanner(System.in);
System.out.println("----------彩票-----------");
System.out.println("请输入身份证号码:");
String id = input.next();
mylottery.setId(id);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String buydate = sdf.format(new Date());
mylottery.setBuydate(buydate);
System.out.println("购买日期:" + mylottery.getBuydate());
boolean b = true;
while (b) {
System.out.println("-----------购买彩票----------");
System.out.println("请输入(1-35)的7个数字以逗号间隔");
String math = input.next();
String[] m = math.split(",");
if (m.length != 7) {
System.out.println("输入的位数不等于7位,请重新输入");
continue;
} else {
Integer[] inte = new Integer[7];
HashSet<Integer> hs = new HashSet<>();
for (int i = 0; i < m.length; i++) {
inte[i] = Integer.parseInt(m[i]);
hs.add(inte[i]);
}
if (hs.size() != 7) {
System.out.println("不能输入重复的数字,请重新输入");
continue;
} else {
mylottery.setBuyno(hs);
input.close();
b = false;
}
}
}
}
static class LotteryBean {
private String id;
private HashSet<Integer> buyno;
private String buydate;
private HashSet<Integer> winno;
private int winmoney;
public LotteryBean() {
super();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public HashSet<Integer> getBuyno() {
return buyno;
}
public void setBuyno(HashSet<Integer> hs) {
this.buyno = hs;
}
public String getBuydate() {
return buydate;
}
public void setBuydate(String buydate) {
this.buydate = buydate;
}
public HashSet<Integer> getWinno() {
return winno;
}
public void setWinno(HashSet<Integer> hs1) {
this.winno = hs1;
}
public int getWinmoney() {
return winmoney;
}
public void setWinmoney(int winmoney) {
this.winmoney = winmoney;
}
}
}