ATM机项目演示

import javax.swing.JOptionPane;


public class atm {


public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "欢迎光临,英国瑞士银行");
boolean islogin = login1();
while (true) {
if (islogin == true) {
String s = JOptionPane.showInputDialog(null,
"1、存款\n2、取款\n3、查询余额\n4、退卡");
int x = Integer.parseInt(s);
switch (x) {
case 1:
savemoney1();
break;
case 2:
getmoney1();
break;
case 3:
showmoney1();
break;
case 4:
JOptionPane.showMessageDialog(null, "请取走你的卡片");
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null, "请输入1-4");
break;
}


}
}
}


public static int money = 5000;


public static void savemoney1() {
String s = JOptionPane.showInputDialog(null, "输入存款金额");
money += Integer.parseInt(s);
int x = JOptionPane.showConfirmDialog(null, "是否显示余额");
if (x == 0) {
showmoney1();
}
}


public static void getmoney1() {
String s = JOptionPane.showInputDialog(null, "请输入取款金额");
int x = Integer.parseInt(s);


if (x > money) {
JOptionPane.showMessageDialog(null, "余额不足");


} else {
money -= x;
int n = JOptionPane.showConfirmDialog(null, "是否显示余额");
if (n == 0) {
showmoney1();
}
}
}


public static void showmoney1() {
JOptionPane.showMessageDialog(null, "余额:" + money);
}


public static boolean login1() {
for (int i = 0; i < 3; i++) {
String s = JOptionPane.showInputDialog(null, "请输入卡号");
int card = Integer.parseInt(s);
String n = JOptionPane.showInputDialog(null, "请输入密码");
int pwd = Integer.parseInt(n);


if (card == 123 && pwd == 456) {
return true;
} else {
JOptionPane.showMessageDialog(null, "卡号或密码错误");
}
}
JOptionPane.showMessageDialog(null, "卡号和密码输入错误超过3次,请联系发卡行");
System.exit(0);
return false;
}


}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值