面向过程编程的ATM提款机

[size=medium][size=medium][/size][color=red][/color][align=center][/align]package com.lovo;

import javax.swing.JOptionPane;
/**
* ATM提款機
* @author WenChuan
*
*/
public class Atm {


public static void main(String[] args) {
// 默认原有的钱
int money = 1000;
// 输入的次数
int counter = 0;
//登陸介面
JOptionPane.showMessageDialog(null, "欢迎使用ATM提款机");

for (counter = 0; counter < 10; counter++) {
/*
* 用戶名和密碼的判斷
*
* */
String userName = JOptionPane.showInputDialog("请输入用户名:");
String passWord = JOptionPane.showInputDialog("请输入密码:");
int password = Integer.parseInt(passWord);
if (userName.equals("abc") && password == 123) {
JOptionPane.showMessageDialog(null, "登陆成功");
break;
} else {
JOptionPane.showMessageDialog(null, "用户名或密码不对,请重新输入");
}
while (counter == 2) {
JOptionPane.showMessageDialog(null, "你是非法用户,吞卡中、、、、");
System.exit(counter);
}
}
/**
* 進入系統操作!!
*/
while (counter < 3) {
String string = JOptionPane.showInputDialog("1-存钱,2-取款,3-查询,4-退出");
int select = Integer.parseInt(string);
/*
* 存款
*
* */
if (select == 1) {
String m = JOptionPane.showInputDialog("请输入存款金额:");
int money3 = Integer.parseInt(m);
money = money + money3;
JOptionPane.showMessageDialog(null, "存款成功,现在金额是" + money + "元");
String b = JOptionPane.showInputDialog("1-继续,2-结束");
int b1 = Integer.parseInt(b);
if (b1 == 1) {
continue;
} else {
break;
}

}
/*
* 取款
*
* */

else if (select == 2) {
while (true) {
String m1 = JOptionPane.showInputDialog("请输入取款金额");
int money2 = Integer.parseInt(m1);
if (money >= money2) {
money = money - money2;
JOptionPane.showMessageDialog(null, "取款成功,现在金额是"
+ money + "元");
break;
} else {
JOptionPane.showMessageDialog(null, "对不起,余额不足,请重新输入");
continue;
}
}
String b = JOptionPane.showInputDialog("1-继续,2-结束");
int b1 = Integer.parseInt(b);
if (b1 == 1) {
continue;
} else {
break;
}
}
/*
* 查詢
*
* */
else if (select == 3) {
JOptionPane.showMessageDialog(null, "你好!你的余额是" + money);
String b = JOptionPane.showInputDialog("1-继续,2-结束");
int b1 = Integer.parseInt(b);
if (b1 == 1) {
continue;
} else {
break;
}
} else if (select == 4) {
break;
} else {
JOptionPane.showMessageDialog(null, "你输入有误,请重新输入");
String b = JOptionPane.showInputDialog("1-继续,2-结束");
int b1 = Integer.parseInt(b);
if (b1 == 1) {
continue;
} else {
break;
}
}
}
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值