9.1AT课堂M笔记

来源:互联网 发布:手机游戏下载java 编辑:程序博客网 时间:2024/05/01 18:10
import java.util.Scanner;


/**ATM存取款*/
public class ATM {


public static void main(String[] args) {
String user="510722";
String pwd="123456"; 
float money=13000.00f;//yu'e
welcome();
boolean isLogin=login(user,pwd);
if(isLogin==true){
 
Scanner sc=new Scanner (System.in);
 
while(true){
System.out.println("1.查询余额2.存款3.取款4.改密5.退出");
int FucType=sc.nextInt();
switch(FucType){
case 1:
searchMoney(money);
break;
case 2:
float s_money=saveMoney();
money=money+s_money;
break;
case 3:
float g_money=getMoney(money);
money=money-g_money;
break;
case 4:
pwd=changePwd(pwd);
System.out.println("现在的密码是"+pwd);break;
case 5:System.exit(0);break;
default:break;
}
}
}
else{
System.exit(0);
}


login(user,pwd);
}
public static void welcome(){//进入界面 可在前面直接输入
System.out.println("-------------------------------------------------");
System.out.println("******************欢迎使用***********************");
System.out.println("                                                 ");
System.out.println("****************BANK OF OLDDRIVER****************");
}
/**登陆*/
public static boolean login(String user,String pwd){
Scanner sc=new Scanner(System.in);
for(int i=3;i>0;i--){

System.out.println("请输入用户名");
String chechUser=sc.next();
System.out.println("请输入密码");
String checkPwb=sc.next();

if(user.equals(chechUser)  &&  pwd.equals(checkPwb)){
System.out.println("登陆成功");
return true;
}else{
System.out.println("用户名或密码错误");
if(i==1){
System.out.println("卡被吞了,请到柜台咨询");
return false;
}
System.out.println("用户名或密码错误!今日剩余次数"+(i-1));
}
}

return false;
}
//余额
public static void searchMoney(float money){
System.out.println("您的余额"+money);
}
//存款
public static float saveMoney(){
System.out.println("存入多少");
Scanner sc=new Scanner(System.in);
float saveMoney=sc.nextFloat();

if(saveMoney>10000){
System.out.println("单次上线为10000.00元");
saveMoney=0;
}
else if(saveMoney<0){
System.out.println("不能存储负数的钱");
saveMoney=0;
}
else if(saveMoney%100!=0){
System.out.println("只能存储100的倍数");
saveMoney=0;
}else{
System.out.println("存款成功");
}

return saveMoney;
}
//取款
public static float getMoney(float nowMoney){
System.out.println("输入取款金额");
Scanner sc=new Scanner(System.in);
float getMoney=sc.nextFloat();

if(getMoney>3000){
System.out.println("单次上线为3000.00元");
getMoney=0;
}
else if(getMoney<0){
System.out.println("不能取负数的钱");
getMoney=0;
}
else if(getMoney%100!=0){
System.out.println("只能存储100的倍数");
getMoney=0;
}else if(getMoney>nowMoney){
System.out.println("余额不足");
}
else{
System.out.println("取款成功");
}
return getMoney;
}
public static String changePwd(String oldPassword){
System.out.println("请输入老密码");
Scanner sc=new Scanner(System.in);
String pwd=sc.next();
if(pwd.equals(oldPassword)){
//老密码正确
System.out.println("请输入新密码");
String newPwd=sc.next();
System.out.println("再次输入新密码");
String newPwd2=sc.next();
if(newPwd.equals(newPwd2)){
System.out.println("修改密码成功");
return newPwd;
}else{
System.out.println("两次密码不一致!请重新设置!");
return oldPassword;
}
}else{
System.out.println("老密码输入错误");
}
return oldPassword;
}
}
0 0
原创粉丝点击