《第10章》

  运用前几章的知识完成快乐摇奖系统的开发。

 

package chapter02;

import java.util.Scanner;

public class Happy{
Scanner input = new Scanner(System.in);
int userchoose = 0; //系统选择菜单
int numcard = 0; //系统自动生成会员卡号
int userCard = 0; //用户输入卡号
int luckyCard = 0;
int max = 9999;
int min = 1000;

String name = ""; //用户名
String pawd = ""; //密码
String userName = "";
String userpswd = "";

boolean ispaly = false;

public void zhuCe(){
//注册
System.out.println("快乐摇奖>注册");
System.out.println("请输入个人注册信息");
System.out.print("用户名:");
name = input.next();
System.out.print("密码:");
pawd = input.next();
System.out.println("注册成功,请记得您的会员卡号");
numcard = (int) (Math.random() * (max - min)) + min;
System.out.println("用户名\t密码\t 会员卡号");
System.out.println(name + "\t" + pawd + "\t" + numcard);

}
public void dengLu(){
//登陆

for (int i = 0; i < 3; i++){
System.out.println("快乐摇奖>登陆");System.out.print("请输入用户名:");
userName = input.next();
System.out.print("请输入密码:");
userpswd = input.next();
if (userName.equals(name) && userpswd.equals(pawd)) {
System.out.println("欢迎您:" + name);
break;
} else {

System.out.println("您的输入有误,请重新输入:");
}

}
}
public void yaoJiang(){
//摇奖
System.out.println("快乐摇奖>摇奖");
System.out.print("请输入您的卡号:");
for(int j=0;j<3;j++){
userCard=0;
userCard = input.nextInt();
if (userCard == numcard) {
System.out.print("本日的幸运数字为:" );

for (int i = 0; i < 4; i++) {
luckyCard = (int) (Math.random() * (max - min)) + min;
System.out.print(luckyCard+"\t");
}

if (userCard == luckyCard){
System.out.println("恭喜成为本日会员!");

}

else {
System.out.println("\n抱歉您不是本日会员!");
}


}
}

}



public void caiDan(){
do {

System.out.println("****欢迎进入快乐摇奖系统****");
System.out.println("\n1.注册\t\n2.登陆\t\n3.抽奖\n");
System.out.println("**********************");
System.out.println("请选择菜单:");
userchoose = input.nextInt();
switch (userchoose) {
case 1:
zhuCe();
break;

case 2:
dengLu();
break;

case 3:

yaoJiang();
break;

}
System.out.print("要继续吗?(y/n):");
String jiXu = input.next();
if (jiXu.equals("y")) {
ispaly = true;
} else {
ispaly = false;

}
} while (ispaly);
System.out.print("系统退出,谢谢使用!");
}


}

 

转载于:https://www.cnblogs.com/dqn-1996-02/p/5068452.html

你可能感兴趣的:(《第10章》)