Java實(shí)現(xiàn)多用戶注冊(cè)登錄的幸運(yùn)抽獎(jiǎng)
本文實(shí)例為大家分享了Java實(shí)現(xiàn)簡(jiǎn)單幸運(yùn)抽獎(jiǎng)的具體代碼,供大家參考,具體內(nèi)容如下








代碼模塊:
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函數(shù):
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("****************歡迎進(jìn)入獎(jiǎng)客富翁系統(tǒng)*******************");
System.out.println(" 1、注冊(cè)");
System.out.println(" 2、登錄");
System.out.println(" 3、抽獎(jiǎng)");
System.out.println("*******************************************************");
System.out.print("請(qǐng)選擇菜單:");
n = in.next();
switch(n) {
//用戶注冊(cè)
case "1": {
userName = null;
userPassword = null;
System.out.println("(獎(jiǎng)客富翁系統(tǒng) >注冊(cè)):");
System.out.print("用戶名:");
String name = in.next();
System.out.print("密 碼:");
String password = in.next();
System.out.print("確認(rèn)密碼:");
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("注冊(cè)成功,請(qǐng)記住您的會(huì)員卡號(hào):");
System.out.println("用戶名 密碼 會(huì)員卡號(hào)");
System.out.println(u.getUserName()+" "+u.getPassword()+" "+u.getVipID());
}
else {
System.out.println("對(duì)不起,您輸入的密碼不一致!");
}
System.out.print("\n繼續(xù)嗎?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("您的輸入為非法輸入,請(qǐng)重新輸入:");
fir = false;
}
}
conf = confirm;
if(conf.equals("n")||conf.equals("N")) {
System.out.println("系統(tǒng)退出,謝謝使用!");
}
}
break;
//用戶登錄
case "2": {
String eName = null;
String ePassword = null;
userName = null;
userPassword = null;
boolean fla = false;
int eVipID = 0;
System.out.println("(獎(jiǎng)客富翁系統(tǒng) >登錄):");
while(fla == false){
System.out.print("用戶名:");
userName = in.next();
System.out.print("密 碼:");
userPassword = in.next();
if(user.isEmpty()) {
System.out.println("您還沒有注冊(cè),請(qǐng)先注冊(cè)!");
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("您輸入的賬號(hào)或密碼有誤,請(qǐng)重新輸入:");
}
flag0 = true;
break;
}
}
if(flag0 == false) {
System.out.println("您還沒有注冊(cè),請(qǐng)先注冊(cè)!");
}
}
}
if(flag0 == true) {
System.out.print("繼續(xù)嗎?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("系統(tǒng)退出,謝謝使用!");
}
}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("您的輸入為非法輸入,請(qǐng)重新輸入:");
}
}
conf = confirm;
if(conf.equals("n")||conf.equals("N")) {
System.out.println("系統(tǒng)退出,謝謝使用!");
}
}
}
break;
//抽獎(jiǎng)
case "3": {
System.out.println("(獎(jiǎng)客富翁系統(tǒng) >抽獎(jiǎng)):");
if(u == null||(userName==null&&userPassword==null)){
System.out.println("您還沒有登錄,請(qǐng)重新登錄!");
System.out.print("繼續(xù)嗎?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("您的輸入為非法輸入,請(qǐng)重新輸入:");
fir = false;
}
}
conf = confirm;
if(conf.equals("n")||conf.equals("N"))
System.out.println("系統(tǒng)退出,謝謝使用!");
}
else{
System.out.println("歡迎"+u.getUserName()+"來(lái)到幸運(yùn)抽獎(jiǎng)!");
System.out.println("您的會(huì)員卡號(hào)為:"+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恭喜你成為本日的幸運(yùn)會(huì)員!");
}
else {
System.out.println("\n抱歉,您不是本日的幸運(yùn)會(huì)員!");
}
System.out.print("繼續(xù)嗎?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("您的輸入為非法輸入,請(qǐng)重新輸入:");
fir = false;
}
}
conf = confirm;
if(conf.equals("n")||conf.equals("N"))
System.out.println("系統(tǒng)退出,謝謝使用!");
}
break;
}
default:{
System.out.println("您的輸入為非法輸入,請(qǐng)重新輸入:");
System.out.print("繼續(xù)嗎?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("您的輸入為非法輸入,請(qǐng)重新輸入:");
fir = false;
}
}
conf = confirm;
if(conf.equals("n")||conf.equals("N"))
System.out.println("系統(tǒng)退出,謝謝使用!");
break;
}
}
}while((conf.equals("Y")||conf.equals("y"))&&(!(n.equals("1"))||!(n.equals("2"))||!(n.equals("3"))));
}
}以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java+mysql用戶注冊(cè)登錄功能
- JAVA簡(jiǎn)單實(shí)現(xiàn)MD5注冊(cè)登錄加密實(shí)例代碼
- Java簡(jiǎn)易登錄注冊(cè)小程序
- JavaWeb實(shí)現(xiàn)用戶登錄與注冊(cè)功能
- JavaWeb實(shí)現(xiàn)用戶登錄與注冊(cè)功能(服務(wù)器)
- JavaWeb實(shí)戰(zhàn)之用Servlet+JDBC實(shí)現(xiàn)用戶登錄與注冊(cè)
- 基于IO版的用戶登錄注冊(cè)實(shí)例(Java)
- Java如何優(yōu)雅的實(shí)現(xiàn)微信登錄注冊(cè)
- javaweb實(shí)現(xiàn)注冊(cè)登錄頁(yè)面
- Java實(shí)現(xiàn)登錄與注冊(cè)頁(yè)面
相關(guān)文章
springboot配置ssl后啟動(dòng)一直是端口被占用的解決
這篇文章主要介紹了springboot配置ssl后啟動(dòng)一直是端口被占用的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
SpringMVC靜態(tài)資源訪問(wèn)問(wèn)題如何解決
這篇文章主要介紹了SpringMVC靜態(tài)資源訪問(wèn)問(wèn)題如何解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11
MyBatis驗(yàn)證多級(jí)緩存及 Cache Aside 模式的應(yīng)用小結(jié)
本文介紹了MyBatis的多級(jí)緩存機(jī)制,包括本地緩存和全局緩存,并通過(guò)Spock測(cè)試框架驗(yàn)證了多級(jí)緩存的實(shí)現(xiàn),本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-12-12
SpringCloud之消息總線Spring Cloud Bus實(shí)例代碼
這篇文章主要介紹了SpringCloud之消息總線Spring Cloud Bus實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-04-04
IDEA自動(dòng)生成TestNG的testng.xml的插件方法
這篇文章主要介紹了IDEA自動(dòng)生成TestNG的testng.xml的插件方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04
深入了解Spring Boot2.3.0及以上版本的Liveness和Readiness功能
這篇文章主要介紹了Spring Boot2.3.0及以上版本的Liveness和Readiness功能示例深入解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10
淺談springboot多模塊(modules)開發(fā)
這篇文章主要介紹了淺談springboot多模塊(modules)開發(fā),詳細(xì)的介紹了springboot多模塊的實(shí)現(xiàn),有興趣的可以了解一下2017-09-09
Java代碼注釋規(guī)范(動(dòng)力節(jié)點(diǎn)整理)
代碼注釋是架起程序設(shè)計(jì)者與程序閱讀者之間的通信橋梁,最大限度的提高團(tuán)隊(duì)開發(fā)合作效率。也是程序代碼可維護(hù)性的重要環(huán)節(jié)之一。下面通過(guò)本文說(shuō)一下我們?cè)谌粘i_發(fā)中使用的代碼注釋規(guī)范2017-03-03

