ATM取款代码

#Sun Apr 01 19:09:52 CST 2018
money=99855000
userName=java
pwd=123

import java.io.FileReader;
import java.io.FileWriter;
import java.util.Properties;
import javax.swing.JOptionPane;
public class atmSystem {
//定义全局变量
public static Properties user=new Properties();
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "欢迎光临");
try{
user.load(new FileReader("ATM.txt"));
}catch(Exception e){
JOptionPane.showMessageDialog(null, "文件夹不存在");
}
boolean a=register();
if (a==false){
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);
}
while(true){
int select=Integer.parseInt(JOptionPane.showInputDialog(null, "1、存款"+"\n"+"2、取款"+"\n"+"3、查询"+"\n"+"4、改密"+"\n"+"5、退出"));
switch(select){
case 1:
deposit();
break;
case 2:
withdrawal();
break;
case 3:
show();
break;
case 4:
amend();
break;
case 5:
System.exit(0);
}
}
}
//登录方法调用
public static boolean register(){
for(int i=0;i<3;i++){
String name=JOptionPane.showInputDialog(null, "请输入用户名");
String pwd=JOptionPane.showInputDialog(null, "请输入密码");
if (name.equals(user.getProperty("userName"))&&pwd.equals(user.getProperty("pwd"))){
return true;
}
else {
JOptionPane.showMessageDialog(null, "用户名或密码错误");
}
}
return false;
}
//写入文件
public static void writer(){
try{
user.store(new FileWriter("ATM.txt"), null);
}catch (Exception e){
JOptionPane.showMessageDialog(null, "文件夹不存在");
}
}
//存款
public static void deposit(){
int money=Integer.parseInt(JOptionPane.showInputDialog(null, "请输入存款金额"));
user.setProperty("money", (Integer.parseInt(user.getProperty("money"))+money)+"");
writer();

}
//取款
public static void withdrawal(){
while(true){
int money=Integer.parseInt(JOptionPane.showInputDialog(null, "请输入取款金额"));
if (money>Integer.parseInt(user.getProperty("money"))){
JOptionPane.showMessageDialog(null, "账号以超支");
}
else{
user.setProperty("money", (Integer.parseInt(user.getProperty("money"))-money)+"");
writer();
break;
}
}
}
//显示
public static void show(){
JOptionPane.showMessageDialog(null, "余额 为:"+user.getProperty("money"));
}
//改密
public static void amend(){
String oldPwd=JOptionPane.showInputDialog(null, "请输入旧密码");
if(oldPwd.equals(user.getProperty("pwd"))==false){
JOptionPane.showMessageDialog(null, "旧密码不正确");
return;
}
String newPwd=JOptionPane.showInputDialog(null, "请输入新密码");
String newPwdAgain=JOptionPane.showInputDialog(null, "请再次输入新密码");
if(newPwd.equals(newPwdAgain)==false){
JOptionPane.showMessageDialog(null, "二次密码不相同");
return;
}
JOptionPane.showMessageDialog(null, "修改密码成功");
user.setProperty("pwd", newPwd);
writer();
}
}

转载于:https://www.cnblogs.com/dmp90/p/8688196.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值