如何做一个简易的ATM机

下图是我做一个简易的ATM机的思路和步骤:(以人性化为原则,再根据生活中实际ATM机补充)

代码实现为:

package lesson816;


import java.util.Scanner;


public class Atm {


public static void main(String[] args) {
// TODO Auto-generated method stub
//初始化用户数据
String userName = "J129";
String passWord = "521314";
float account = 10000.0f;

//欢迎界面
System.out.println("********************");
System.out.println("**   欢迎来到helloworld银行      **");
System.out.println("********************");
System.out.println("********************");

//实现登陆
Scanner scan = new Scanner(System.in);

boolean flag = false;
for(int i=0;i<3;i++){
System.out.println("请输入用户名:");
String inputName = scan.next();
System.out.println("请输入密码:");
String inputPassWord = scan.next();

if(inputName.equals(userName) && inputPassWord.equals(passWord)){
System.out.println("登陆成功!");
flag = !flag;
break;
}else {
if(i==2){
System.out.println("您没有机会了,登陆失败!");
break;
}
System.out.print("密码和账号有误,");
System.out.println("您还有"+(2-i)+"机会");

}
}

//基本选项(1.查询余额;2.取款;3.存款;4.修改密码;5.退出)

while(flag){
System.out.println();
System.out.println("1.查询余额");
System.out.println("2.取款");
System.out.println("3.存款");
System.out.println("4.修改密码");
System.out.println("5.退出");

System.out.println("请选择您要操作的选项:");
int num = scan.nextInt();
int qk;
int ck;
switch(num){
case 1:
System.out.println("您卡上余额为:"+account);
break;
case 2:
System.out.println("请选择您要取款的数额:");
qk = scan.nextInt();
if(qk<0){
System.out.println("不能取负值的存款");
}else if(qk >= account){
System.out.println("余额不足");
}else if(qk%100==0){
account-=qk;
System.out.println("取出"+qk+"成功");
}else{
System.out.println("取款失败,请取出100的整数");
}
break;
case 3:
System.out.println("请选择您要存款的数额:");
ck = scan.nextInt();
if(ck<0){
System.out.println("不能取负值的存款");
}else if(ck%100==0){
account +=ck;
System.out.println("存入"+ck+"成功");
}else{
System.out.println("存款失败,请存入100的整数");
}
break;
case 4:
System.out.println("请输入旧密码:");
String oldPassWord = scan.next();
if(oldPassWord.equals(passWord)){
System.out.println("请输入新密码:");
String newPassWord1 = scan.next();
System.out.println("请再次输入新密码:");
String newPassWord2 = scan.next();

if(newPassWord1.equals(newPassWord2)){
passWord = newPassWord1;
System.out.println("修改成功");
}else{
System.out.println("修改失败,两次新密码输入不一致!");
}
}else{
System.out.println("修改失败,旧密码输入有误!");
}
break;
case 5:
System.out.println("退出");
System.exit(0);
}
}
}
}

阅读更多
文章标签: java语法 ATM
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭