//模拟ATM机的操作,密码输入3次错误,提示退出,(每次错误提示还有几次机会)
//判读卡上是否还有余额,余额不足,直接提示余额不足100块不能提取现金
//如果输入的金额大于余额,或者%100!=0,金额不足或者输入金额不正确
/*String pass = ""; //保存用户输入密码
int amount = 0; //取款金额
int cardYue = 1000; //银行卡余额
String password = "111111"; //用户密码
int count = 0; //记录密码输入次数
boolean isPass = false; //密码是否通过验证
String choice = null;
while(count < 3 && !isPass){
System.out.print("请输入密码:");
pass = input.next();
if(!password.equals(pass)){
count++;
continue;
}
isPass = true; //密码通过验证
do{
System.out.print("请输入金额:");
amount = input.nextInt();
if(amount <= cardYue && amount % 100 == 0){
System.out.println("您取了" +amount+ "元");
cardYue -= amount;
System.out.println("卡上余额还剩:" + cardYue);
if(cardYue < 100){
System.out.println("余额已不足,要继续业务办理请到柜台!");
break;
}
}else{
System.out.println("您输入金额的金额不合法!");
}
System.out.println("你要继续操作吗?");
choice = input.next();
}while(choice.equals("y"));
}
if(!isPass){ //用户输入了3次错误密码
System.out.print("密码错误,请取卡!");
}*/
/*
* ***大富翁抽奖系统***
* String answer = null;
String uName = null; //注册的用户名
String uPwd = null; //注册的密码
int cardNum = 0;
int min = 1000;
int max = 9999;
boolean isRegister = false;
boolean isLogin = false;
boolean isLucky = false;
do{
System.out.println("欢迎使用大富翁抽奖系统");
System.out.println("1.注册");
System.out.println("2.登录");
System.out.println("3.抽奖");
System.out.println("请选择:(1-3)");
int choice = input.nextInt();
switch(choice){
case 1:
System.out.println("大富翁抽奖系统>>>1.注册");
System.out.println("请输入个人信息");
System.out.println("请输入用户名:");
uName = input.next();
System.out.println("请输入密码:");
uPwd = input.next();
cardNum = (int)(Math.random()*(max - min))+min;
isRegister = true;
System.out.println("用户名\t密码\t卡号");
System.out.println(uName + "\t" + uPwd + "\t" + cardNum);
break;
case 2:
System.out.println("大富翁抽奖系统>>>2.登录");
if(isRegister){
for(int i=1; i<=3; i++){
System.out.println("请输入你的用户名:");
String inputName = input.next();
System.out.println("请输入你的密码");
String inputPwd = input.next();
if(inputName.equals(uName) && inputPwd.equals(uPwd)){
isLogin = true;
System.out.println("欢迎你:" + uName);
break;
}else if(i<3){
System.out.println("输入用户名或密码错误,你还有"+(3-i)+"次机会");
}else{
System.out.println("三次都输入错误...退出登录");
}
}
}else{
System.out.println("你还没有注册,请先注册!");
}
break;
case 3:
System.out.println("大富翁抽奖系统>>>3.抽奖");
if(!isLogin){
System.out.println("你还没有登录,请先登录!");
}else{
String str = "";
for(int i=1; i<=4; i++){
int random = (int) (Math.random()*(max-min)) + min;
str += random + "\t";
if(random == cardNum){
isLucky = true;
}
}
System.out.println("中奖号码是:" + str);
System.out.println("你的卡号是:" + cardNum);
if(isLucky){
System.out.println("恭喜你中奖了。。。");
}else{
System.out.println("没有中奖...");
}
}
break;
default:
System.out.println("输入错误....");
}
System.out.println("是否继续(y/n)");
answer = input.next();
}while(answer.equals("y"));
System.out.println("程序退出...谢谢使用!");
input.close();*/
循环的综合应用
最新推荐文章于 2021-12-07 20:59:39 发布