贴一篇自己写的ATM机

package com.atmTest;


import javax.swing.JOptionPane;


public class ATM {
User[] u={new User("123","123",3000),new User("456","456",6000),new User("111","111",5000)}; 

public User current;
public ATM(){
JOptionPane.showMessageDialog(null, "欢迎使用XX银行");

current=Login();

if(current==null){
JOptionPane.showMessageDialog(null, "谢谢使用,再见");
System.exit(0);
}
while(true){
String input=JOptionPane.showInputDialog(null,"1.取款\n2.存款\n3.查询\n4.退出");
int in=Integer.parseInt(input);

switch (in) {
case 1:
CheckOut();
break;
case 2:
CheckIn();
break;


case 3:
Show();
break;


case 4:
JOptionPane.showMessageDialog(null, "谢谢使用,再见");
System.exit(0);
break;


default:
break;
}
}
}



private void CheckOut() {
String q=JOptionPane.showInputDialog(null,"请输入取钱额");
int out = Integer.parseInt(q);
if(current.money<out){JOptionPane.showMessageDialog(null, "滚犊子,都没钱还嘚瑟!");}
else {

current.money-=out;
Show();
}
}


/***
 * 存钱
 */
private void CheckIn() {
String c=JOptionPane.showInputDialog(null,"输入存钱额");
int M= Integer.parseInt(c);
current.money+=M;
Show();
}






/***
* 查询金额
*/
private void Show() {
JOptionPane.showMessageDialog(null,"当前余额"+ current.money);
}








/***
* 登陆框
* @return
*/
public User Login(){

for (int i = 0; i < 3; i++) {
String userName = JOptionPane.showInputDialog(null, "请输入账户");
String passWord = JOptionPane.showInputDialog(null, "请输入密码");
for (int j = 0; j < u.length; j++) {

if (userName.equals(u[j].code) && passWord.equals(u[j].pwd)) {
JOptionPane.showMessageDialog(null, "登陆成功,欢迎使用XX银行");
return u[j];

}


}
JOptionPane.showMessageDialog(null, "登陆失败请重新输入");

}JOptionPane.showMessageDialog(null, "登陆超过三次,以吞卡");

return null;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值