Java Simple Drawing System Small Project

  • 2021-06-28 09:09:36
  • OfStack

The specific code of the Java simple lottery system is shared for your reference, which is as follows:

Requirements:

Implement a lottery system

1 Registration

2 Logon

3 Draws

Must register before landing before drawing prizes

Randomly generate 4 random numbers as lucky card numbers

User Name Password Entry Judges that there are only 3 chances for a user to sign in after registering

Need to do 2 more typos 3 more typos can no longer log in

Generate 10 random numbers to judge the random numbers registered by the user

The code is as follows:


import java.util.*;
 
public class Homeworktest {
 
 public static void main(String[] args) {
 Scanner cin=new Scanner(System.in);
 Random rand=new Random();
 int num,i,Key,j,before=0,count,len=0,L=0;
 int[] data=new int[10];
 String[][] book=new String[10][2]; //存储用户注册信息
 String ID,Temp;
 System.out.println("**********");
 System.out.println("0 退出\n1 注册\n2 登陆\n3 抽奖");
 System.out.println("**********");
 while(true){
 System.out.println("请输入Key:");
 Key=cin.nextInt();
 cin.nextLine();
 if(Key == 0){
 System.out.println("抽奖系统已退出,欢迎您再次使用!");
 break;
 }
 else if(Key == 1){
 before=0;
 System.out.println("请输入您要建立的账号:");
 ID=cin.nextLine();
 i=len++;
 book[i][0]=ID;
 while(true){
 System.out.println("请设置您的密码:");
 ID=cin.nextLine();
 book[i][1]=ID;
 System.out.println("请确认您的密码:");
 for(j=3;j>0;j--){
 ID=cin.nextLine();
 if(book[i][1].equals(ID)){
 System.out.println("恭喜您注册成功!");
 System.out.println("您的账号是:"+book[i][0]+"\n您的密码是:"
 +book[i][1]+"\n请妥善保管!");
 break;
 }
 else if(j>1)
 System.out.println("对不起,两次输入密码不符,您还有"
 +(j-1)+"次机会!请重新输入:");
 else
 System.out.println("该密码已重置!");
 }
 if(j!=0) break;
 }
 }
 else if(Key == 2){
 before=0;
 for(i=3;i>0;i--){
 System.out.println("请输入您的账号:");
 ID=cin.nextLine();
 System.out.println("请输入您的密码:");
 Temp=cin.nextLine();
 for (j = 0; j < len; j++) {
 if(ID.equals(book[j][0]) && Temp.equals(book[j][1]))
 break;
 }
 if(j==book.length){
 if(i>1)
 System.out.println("对不起,登陆失败!你还有"+(i-1)+"次机会.");
 else{
 num=0;
 for (int k = 0; k < book.length-1; k++) {
 if(num == 0 && ID.equals(book[k][0])) num=1;
 if(num == 1){
 book[k][0]=book[k+1][0];
 book[k][1]=book[k+1][1];
 }
 }
 System.out.println("账号:"+ID+"已被冻结,不能继续使用!");
 }
 }
 else{
 System.out.println("恭喜您登陆成功!");
 before=1;
 L=j;
 break;
 }
 }
 }
 else if(Key == 3){
 if(before == 1){
 for(i=0;i<data.length;i++)
 data[i]=rand.nextInt(9)+1;
 System.out.println("您的号码分别是:");
 for(i=count=0;i<4;i++){
 num=rand.nextInt(9)+1;
 System.out.print(num+" ");
 for(j=0;j<data.length;j++)
 if(data[j] == num)
 {
 count++;
 break; //可能有多个相同
 }
 }
 System.out.println("");
 System.out.println(book[L][0]+":");
 switch(count){
 case 4:System.out.println("恭喜您中特等奖!");break;
 case 3:System.out.println("恭喜您中1等奖!");break;
 case 2:System.out.println("恭喜您中2等奖!");break;
 case 1:System.out.println("恭喜您中3等奖!");break;
 default:System.out.println("很遗憾,您未中奖!");break;
 }
 }
 else
 System.out.println("对不起,您尚未登陆账号,不能参与抽奖活动!");
 }
 }
 }
}

Related articles: