首页 > 代码库 > ATM
ATM
package duzhaonan;
import java.util.Scanner;
import javax.swing.JOptionPane;
class Account{//创建的账户类
String biaoshifu,name,date,password;
double ye;
Account(String a,String b,String c,String d,double e){
biaoshifu=a;
name=b;
date=c;
password=d;
ye=e;
}
Account(){
biaoshifu="1";
name="1";
date="2016/11/11";
password="123456";
ye=10;
}
public void qukuan(){//取款
int i=0;
String s=JOptionPane.showInputDialog("取款!从100、500、1000、1500、2000、5000、0(其他金额)"
+ "、#(退卡)、*(返回操作)中选择输入一项");
switch(s){
case "100":i=100;break;
case "500":i=500;break;
case "1000":i=1000;break;
case "1500":i=1500;break;
case "2000":i=2000;break;
case "5000":i=5000;break;
case "0":{String s1=JOptionPane.showInputDialog("输入需要取款数额");
i=Integer.parseInt(s1);};break;
case "#":tuika();break;
case "*":break;
}
if((ye-i)>=0){
ye=ye-i;
JOptionPane.showMessageDialog(null, "取款成功!您的余额为 " + ye, "Results",
JOptionPane.PLAIN_MESSAGE );}
else
JOptionPane.showMessageDialog(null, "余额不足,取款失败!", "Results",
JOptionPane.PLAIN_MESSAGE );
tuika();//退卡
}
public void cunkuan(){//存款
String s1=JOptionPane.showInputDialog("输入需要存款数额");
int i=Integer.parseInt(s1);
ye=ye+i;
JOptionPane.showMessageDialog(null, "存款成功!您的余额为 " + ye,
"Results",JOptionPane.PLAIN_MESSAGE );
}
public void zhuanzhang(){//转账
String s1=JOptionPane.showInputDialog("输入对方账号");
if(cunzai(s1)==1){
String S=JOptionPane.showInputDialog("输入转账金额");
int i=Integer.parseInt(S);
if((ye-i)>=0){
ye=ye-i;
JOptionPane.showMessageDialog(null, "转账成功!您的余额为 " + ye,
"Results",JOptionPane.PLAIN_MESSAGE );
}
else
JOptionPane.showMessageDialog(null, "余额不足,取款失败!", "Results",
JOptionPane.PLAIN_MESSAGE );
}
else
JOptionPane.showMessageDialog(null, "账户不存在 " , "Results",JOptionPane.PLAIN_MESSAGE );
}
public static void tuika(){//执行退卡操作
}
public int cunzai(String s){//连接数据库判断账号是否存在
int i=1;
return i;
}
}
public class ATM {
public static void main(String[] args){
Account a=new Account();
String s="*****************************************\n";
s=s+" 模拟银行ATM系统 \n";
s=s+"*****************************************\n";
s=s+" 1、存款\n";
s=s+" 2、取款\n";
s=s+" 3、转账\n";
s=s+" 4、输入4结束\n";
do{
String str=JOptionPane.showInputDialog(s);
int i=Integer.parseInt(str);
if(i==1)
a.cunkuan();
else if(i==2)
a.qukuan();
else if(i==3)
a.zhuanzhang();
else
break;
}while(true);
}
}
ATM