Java 实验彩票Lottery 的实现的报告

package com.xuyaowen.Lottery;


import java.util.*;


class LMachine{
private int[] lotteryNum = new int[7];
private int succeedNum = 0;
LMachine(){
System.out.println("彩票机欢迎你的到来!");
}

private void makeLottery(){
for(int i=0; i<7; i++){
double tmp = new Random().nextDouble();
lotteryNum[i] = (int) (tmp*35+1);
}

sortNum();
printLottery();
//直接输出排序后的结果;
}
private void sortNum(){
for(int i=0; i<7; i++)
for(int j=0; j<7-i-1; j++){
if(lotteryNum[j+1]< lotteryNum[j]){
int tt = lotteryNum[j+1];
lotteryNum[j+1] = lotteryNum[j];
lotteryNum[j] = tt;
}
}
}

private String printLottery(){
System.out.println("彩票机中的现在的中奖号码是:");
for(int i=0; i<7; i++){
System.out.print(lotteryNum[i]+" ");
}
System.out.println();
return "已经产生输出";
}

private void checkLottery(int[] userNum){

for(int i=0; i<7; i++){
if(userNum[i] == lotteryNum[i]){
this.succeedNum++;
}
}
showReward();
}

protected void showReward(){
System.out.println();
System.out.println("你的中奖的结果是");
if(succeedNum>0&&succeedNum<=3){
System.out.println("你获得三等奖");
}
else if(succeedNum>3&&succeedNum<=5){
System.out.println("你获得二等奖");
}
else if(succeedNum>5&&succeedNum<=6){
System.out.println("你获得一等奖");
}
else if(succeedNum == 7){
System.out.println("你获得特等奖");
}
else{
System.out.println("谢谢使用,然而并没有获奖!");
}
}

public void run(){
int[] userNum = new int[7];
System.out.println("请输入你想输入的号码,来使用我们的产品中奖!");
for(int i = 0; i<7; i++){
userNum[i] = new Scanner(System.in).nextInt();
}
makeLottery();
checkLottery(userNum);
System.out.println();
System.out.println("本次抽奖结束,谢谢你使用抽奖机!");
System.out.println();
}
}


//用于测试彩票机的类;
public class Lottery {
public static void main(String[] args){

LMachine machine = new LMachine();
while(true){
System.out.println("欢迎你的使用!");
System.out.println("如果想直接跳出程序,请直接关闭!");
machine.run();
}


}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值