欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java实现多用户注册登录的幸运抽奖

程序员文章站 2022-06-21 14:07:53
本文实例为大家分享了java实现简单幸运抽奖的具体代码,供大家参考,具体内容如下代码模块:user类:package test1;public class user { private string...

本文实例为大家分享了java实现简单幸运抽奖的具体代码,供大家参考,具体内容如下

Java实现多用户注册登录的幸运抽奖Java实现多用户注册登录的幸运抽奖Java实现多用户注册登录的幸运抽奖Java实现多用户注册登录的幸运抽奖Java实现多用户注册登录的幸运抽奖Java实现多用户注册登录的幸运抽奖Java实现多用户注册登录的幸运抽奖Java实现多用户注册登录的幸运抽奖

代码模块:

user类:

package test1;

public class user {
 private string username;
 private string password;
 private int vipid;
 
 public user(string username,string password,int vipid) {
 this.username = username;
 this.password = password;
 this.vipid = vipid;
 }
 
 public string getusername() {
 return username;
 }
 public void setusername(string username) {
 this.username = username;
 }
 public string getpassword() {
 return password;
 }
 public void setpassword(string password) {
 this.password = password;
 }
 public int getvipid() {
 return vipid;
 }
 public void setvipid(int vipid) {
 this.vipid = vipid;
 }
}

main函数:

package test1;

import java.util.arraylist;
import java.util.random;

import java.util.scanner;


public class testuser {

 private static scanner in;
 public static void main(string[] args) {
 // todo auto-generated method stub
 arraylist<user> user = new arraylist<user>();
 user u = null;
 string conf = null;
 string username = null;
 string userpassword = null;
 string n;
 boolean flag = false;
 boolean flag0 = false;
 int[][] a = new int[2][5];
 in = new scanner(system.in);
 for(int i=0;i<2;i++) {
  for(int j=0;j<5;j++) {
  random rand = new random();
  a[i][j] = rand .nextint(9999) + 1000;
  }
 }
 do {
  
  system.out.println("****************欢迎进入奖客富翁系统*******************");
  system.out.println("                                 1、注册");
  system.out.println("                                 2、登录");
  system.out.println("                                 3、抽奖");
  system.out.println("*******************************************************");
  
  
  system.out.print("请选择菜单:"); 

   n = in.next();
   
  switch(n) {
   //用户注册
   case "1": {
   username = null;
   userpassword = null;
   system.out.println("(奖客富翁系统 >注册):");
   system.out.print("用户名:");
   string name = in.next();
   system.out.print("密 码:");
   string password = in.next();
   system.out.print("确认密码:");
   string repassword = in.next();
   if(password.equals(repassword)) {
    random rand = new random();
    int randnumber = rand .nextint(9000) + 1000;
    u = new user(name,password,randnumber);
    user.add(u);
    system.out.println("注册成功,请记住您的会员卡号:");
    system.out.println("用户名        密码       会员卡号");
    system.out.println(u.getusername()+"      "+u.getpassword()+"      "+u.getvipid());
   }
   else {
    system.out.println("对不起,您输入的密码不一致!");
   }
   
   system.out.print("\n继续吗?y/n:");
   
   string confirm = null;
   boolean fir = false;
   while(fir == false) {
    confirm = in.next();
    if(confirm.equals("y")||confirm.equals("y")||confirm.equals("n")||confirm.equals("n")) {
    fir = true;
    break;
    }
    else {
    system.out.print("您的输入为非法输入,请重新输入:");
    fir = false;
    }
   }
   
   conf = confirm;
   if(conf.equals("n")||conf.equals("n")) {
    system.out.println("系统退出,谢谢使用!");
   }
   }
   break;
   //用户登录
   case "2": {
   string ename = null;
   string epassword = null;
   username = null;
   userpassword = null;
   boolean fla = false;
   int evipid = 0;
   system.out.println("(奖客富翁系统 >登录):");
   while(fla == false){
    system.out.print("用户名:");
    username = in.next();
    system.out.print("密 码:");
    userpassword = in.next();
    if(user.isempty()) {
    system.out.println("您还没有注册,请先注册!");
    flag0 = true;
    fla = true;
    }else {
    for(user e: user) {
     if(username.equals(e.getusername())) {
     if(username.equals(e.getusername())&&userpassword.equals(e.getpassword())) { 
      
      ename = e.getusername();
      epassword = e.getpassword();
      evipid = e.getvipid();
      fla = true;
      system.out.println("欢迎您:"+ename);
      
     }else {
      system.out.println("您输入的账号或密码有误,请重新输入:");
     }
     flag0 = true;
     break;
     }

    }
    
    if(flag0 == false) {
     system.out.println("您还没有注册,请先注册!");
    }
    
    }
    
   }
   
   if(flag0 == true) {
    
    system.out.print("继续吗?y/n:");
    string confirm = in.next();
    conf = confirm;
    if(conf.equals("y")||conf.equals("y")) {
    u= new user(ename,epassword,evipid);
    }
    else if(conf.equals("n")||conf.equals("n")) {
    system.out.println("系统退出,谢谢使用!");
    }
   }else {
    string confirm = null;
    boolean fir = false;
    while(fir == false) {
    confirm = in.next();
    if(confirm.equals("y")||confirm.equals("y")||confirm.equals("n")||confirm.equals("n")) {
     fir = true;
     break;
    }
    else {
     system.out.print("您的输入为非法输入,请重新输入:");
    }
    }
    conf = confirm;
    if(conf.equals("n")||conf.equals("n")) {
    system.out.println("系统退出,谢谢使用!");
    }
   }
   
   }
   break;
   //抽奖
   case "3": {
   system.out.println("(奖客富翁系统 >抽奖):");
   
   if(u == null||(username==null&&userpassword==null)){
    system.out.println("您还没有登录,请重新登录!");
    system.out.print("继续吗?y/n:");
    string confirm = null;
    boolean fir = false;
    while(fir == false) {
    confirm = in.next();
    if(confirm.equals("y")||confirm.equals("y")||confirm.equals("n")||confirm.equals("n")) {
     fir = true;
     break;
    }
    else {
     system.out.print("您的输入为非法输入,请重新输入:");
     fir = false;
    }
    }
    conf = confirm;
    if(conf.equals("n")||conf.equals("n"))
    system.out.println("系统退出,谢谢使用!");
   }

   else{
    system.out.println("欢迎"+u.getusername()+"来到幸运抽奖!");
    system.out.println("您的会员卡号为:"+u.getvipid());
    for(int i=0;i<2;i++) {
    for(int j=0;j<5;j++) {
     system.out.print(a[i][j]+" ");
     if(u.getvipid() == a[i][j]) {
     flag = true;
     break;
     }else {
     flag=false;
     }
    }
    if(flag == true)
     break;
    }
    if(flag == true) {
    system.out.println("\n恭喜你成为本日的幸运会员!");
    }
    else {
    system.out.println("\n抱歉,您不是本日的幸运会员!");
    }
    system.out.print("继续吗?y/n:");
    string confirm = null;
    boolean fir = false;
    while(fir == false) {
    confirm = in.next();
    if(confirm.equals("y")||confirm.equals("y")||confirm.equals("n")||confirm.equals("n")) {
     fir = true;
     break;
    }
    else {
     system.out.print("您的输入为非法输入,请重新输入:");
     fir = false;
    }
    }
    conf = confirm;
    if(conf.equals("n")||conf.equals("n"))
    system.out.println("系统退出,谢谢使用!");
   }
   
   break;
   }
   
   default:{
   system.out.println("您的输入为非法输入,请重新输入:");
   system.out.print("继续吗?y/n:");
   string confirm = null;
   boolean fir = false;
   while(fir == false) {
    confirm = in.next();
    if(confirm.equals("y")||confirm.equals("y")||confirm.equals("n")||confirm.equals("n")) {
    fir = true;
    break;
    }
    else {
    system.out.print("您的输入为非法输入,请重新输入:");
    fir = false;
    }
   }
   conf = confirm;
   if(conf.equals("n")||conf.equals("n"))
    system.out.println("系统退出,谢谢使用!");
   break;
   
   }
  }
  
 }while((conf.equals("y")||conf.equals("y"))&&(!(n.equals("1"))||!(n.equals("2"))||!(n.equals("3"))));
 }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

相关标签: java 抽奖