做出来的第一个代码 虽有很多要改进 但是自己独立完成的还是很有成就感
import java.util.Scanner;
public class YingHangDengLu {
public static void main(String[] args) {
// TODO Auto-generated method stub
//提示用户三次可用登录机会。
String isuserName = "hupeng";
int isuserPassword = 123456;
boolean result = true;
int count = 1;//?为甚么我只有用1才能控制到三次。自己都没明白。
System.out.println("欢迎来到中国银行ATM系统中心"+"\t"
+ "请登录");
do{
count++;
System.out.println("用户名:");
Scanner input = new Scanner(System.in);
String userName = input.next();
System.out.println("密码:");
Scanner input1 = new Scanner(System.in);
int userPassword = input.nextInt();
if(count > 3){
System.out.println("机会已用完");
result = false;
}else{
if(userName.equals(isuserName) && userPassword==isuserPassword){
System.out.println("恭喜你,登录成功!");
result = false;
System.out.println("请选择服务:1.查询余额"+"\t"+"2.取款"+"\t"+"3.存款");
//Scanner input = new Scanner(System.in);
int choose = input.nextInt();
double leftMoney = 100.00;
switch(choose){
case 1:
System.out.println("您的余额是:"+leftMoney+"元");
System.out.println("y返回到主界面,n退出系统。");
String choose1 = input.next();
if(choose1=="y"){System.err.println("返回到主界面");}//?怎么可以真正的回到主界面?for?
else if (choose1=="n"){System.err.println("欢迎下次光临");}
break;
case 2:
System.out.println("输入您的取款金额:");
double takeMoney = input.nextDouble();
if(takeMoney<=leftMoney){
double endSaveMoney =leftMoney-takeMoney;
System.out.println("当前卡内余额是:"+endSaveMoney+"元");}
else if(takeMoney>leftMoney){System.out.println("您的余额不足。");}
System.out.println("y返回到主界面,n退出系统。");
String choose2 = input.next();
if(choose2=="y"){System.err.println("返回到主界面");}//?怎么可以真正的回到主界面?for?
else if (choose2=="n"){System.err.println("欢迎下次光临");}
break;
case 3:
System.out.println("输入您的存款金额:");
double saveMoney = input.nextDouble();
leftMoney += saveMoney;
System.out.println("您输入的存款金额是:"+saveMoney+"元"+"当前余额"+leftMoney);
System.out.println("y返回到主界面,n退出系统。");
String choose3 = input.next();
if(choose3=="y"){System.err.println("返回到主界面");}//?怎么可以真正的回到主界面?for?
else if (choose3=="n"){System.err.println("欢迎下次光临");}
break;
}
}
}
}while(result);
}
}
浙公网安备 33010602011771号