您的位置:首页 > 编程语言 > Java开发

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

2015-05-06 00:42 447 查看
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();

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: