菜单
package com.xxx.xxx;
import java.util.Scanner;
public class Menu {
public static void main(String[] args) {
showMune();
}
public static void showMune(){
Scanner sc = new Scanner(System.in);
System.out.println("欢迎进入奖客富翁系统");
System.out.println("1.注册");
System.out.println("2.登录");
System.out.println("3.抽奖");
System.out.println("*************");
}
}
注册
/**
* Project
Name:Demo
* File Name:Register.java
* Package
Name:com.xxx.xxx
* Date:2019年4月13日上午11:14:46
* Copyright (c) 2019,
924127149@qq.com All Rights Reserved.
*
*/
package com.xxx.xxx;
import java.util.Scanner;
public class Register {
static Menu menu = new Menu();
static Login login = new Login();
static LuckDraw luckdraw = new LuckDraw();
public static String userName;//用户名
public static String passWord;//密码
public static String b;
public static String c;
public static void register(){
Menu menu = new Menu();
int max=9999;
int min=1000;
int cardNumber;
cardNumber = (int)(Math.random()*(max-min)) +min;
Scanner sc = new Scanner(System.in);
System.out.println("请选择菜单:");
int a = sc.nextInt();
if(a==1){
System.out.println("[奖客富翁系统 > 注册]");
System.out.println("继续吗?(y/n)");
b = sc.next();
if(b.equals("y")){
System.out.println("请填写个人信息:");
System.out.println("用户名:");
userName = sc.next();
System.out.println("密码:");
passWord = sc.next();
System.out.println("注册成功,请记好您的会员卡号");
System.out.println("用户名"+"\t"+"密码"+"\t"+"会员卡号");
System.out.println(userName+"\t"+passWord+"\t"+cardNumber);
System.out.println("继续吗?(y/n)");
c = sc.next();
if(c.equals("y")){
menu.showMune();
}else{
System.out.println("系统退出,谢谢使用!");
}
}else{
System.out.println("系统退出,谢谢使用!");
}
}else if(a==2){
System.out.println("请先注册!");
menu.showMune();
register();
}else if(a==3){
System.out.println("请先注册!");
menu.showMune();
register();
}
else{
System.out.println("输入错误!");
menu.showMune();
register();
}
}
}
登录
/**
* Project
Name:Demo
* File Name:Login.java
* Package
Name:com.xxx.xxx
* Date:2019年4月13日上午11:38:32
* Copyright (c) 2019,
924127149@qq.com All Rights Reserved.
*
*/
package com.xxx.xxx;
import java.util.Scanner;
public class Login {
public static String b;
public static void login(){
Menu menu = new Menu();
Register re = new Register();
Scanner sc = new Scanner(System.in);
System.out.println("请选择菜单:");
int a = sc.nextInt();
if(a==2){
for (int i = 0; i < 3; i++) {
System.out.println("请输入用户名:");
String name = sc.next();
System.out.println("请输入密码:");
String passWord = sc.next();
if(name.equals(Register.userName) && passWord.equals(Register.passWord)){
System.out.println("欢迎您:"+name);
break;
}else if(i<2) {
System.out.println("用户名或者密码错误!");
System.out.println("还有"+(2-i)+"次机会");
continue;
}else{
System.out.println("登录失败,退出系统!");
}
}
System.out.println("继续吗?(y/n)");
b = sc.next();
if(b.equals("n")){
System.out.println("系统退出,谢谢使用!");
}
}else{
System.out.println("输入错误!");
System.out.println("请先登录!");
menu.showMune();
login();
}
}
}
抽奖方法
package com.xxx.xxx;
import java.util.Scanner;
public class LuckDraw {
public static void draw(){
Menu menu=new Menu();
int num1,num2,num3,num4,num5;
int max = 9999;
int min = 1000;
num1 = (int)(Math.random()*(max-min)) +min;
num2 = (int)(Math.random()*(max-min)) +min;
num3 = (int)(Math.random()*(max-min)) +min;
num4 = (int)(Math.random()*(max-min)) +min;
num5 = (int)(Math.random()*(max-min)) +min;
Scanner sc = new Scanner(System.in);
menu.showMune();
System.out.println("请选择菜单:");
int b = sc.nextInt();
if(b==3){
System.out.println("请输入您的卡号:");
String num = sc.next();
System.out.println("本日的幸运数字为:"+num1+","+num2+","+num3+","+num4+","+num5);
if(num.equals(num1) || num.equals(num2) || num.equals(num3) || num.equals(num4) || num.equals(num5)){
System.out.println("恭喜您!中奖啦!为本日幸运会员!");
}else{
System.out.println("抱歉!您不是本日的幸运会员!");
}
}else{
System.out.println("输入错误!");
System.out.println("是否重新输入(y/n)");
String c = sc.next();
if(c.equals("y")){
draw();
}else{
System.out.println("退出系统!");
}
}
System.out.println("继续吗?(y/n)");
String d = sc.next();
if(d.equals("n")){
System.out.println("系统退出,谢谢使用!");
}else{
draw();
}
}
}
测试
package com.xxx.xxx;
public class Test {
public static void main(String[] args) {
Menu menu=new Menu();
Register register = new Register();
Login login = new Login();
LuckDraw luckdraw = new LuckDraw();
menu.showMune();
register.register();
if(register.b.equals("y")){
if(register.c.equals("y")){
login.login();
if(login.b.equals("y")){
luckdraw.draw();
}
}
}
}
}
java幸运抽奖项目
最新推荐文章于 2023-09-11 21:50:34 发布