ll银行ATM系统的设计与实现

package r;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import javax.swing.*;
public class Cash
{
 public static void main( String args[] )
          {
          int cardNum1 = 1;
          int password1 = 1; 
          int cardNum = 123456;//信用卡号
          int password = 123456;//密码
          String str1 = "";
          String str2 = "";
          String str3 = "";
          double cash = 0; 
          int money = 0;
          int i = 1; 
          double rate = 0.0023;
do
        {
 
str1=JOptionPane.showInputDialog("账号:"+"\n");//输入个人信息
        cardNum1=Integer.parseInt(str1); 
str2=JOptionPane.showInputDialog("密码:"+"\n");//输入个人信息
        password1=Integer.parseInt(str2);
        if((cardNum1==cardNum)&&(password1==password))
        break;
        else if((cardNum1!=cardNum)||(password1!=password))
        { 
        JOptionPane.showMessageDialog(null,"错误!请重输");
        str1=JOptionPane.showInputDialog("账号:"+"\n");//读入数据
        cardNum1=Integer.parseInt(str1); 
        str2=JOptionPane.showInputDialog("密码:"+"\n");//读入数据
        password1=Integer.parseInt(str2);
	    if((cardNum1!=cardNum)&&(password1!=password))
	    {
	    	JOptionPane.showMessageDialog(null,"两次输入错误!请退出!!"+"\n"+"卡被吞!");
	    	System.exit(0);
	    } 
	    else System.exit(0);
	    }
	    else System.exit(0);
        }


while( i>0 );
int choise; 
while( i==1 )
{
do
{
	{
String inputChoise = 
JOptionPane.showInputDialog ( "\t请输入您选择的项目代号:\n" +
"\t\t 1 查询余额\n" +
"\t\t 2 存款\n" +
"\t\t 3 取款\n" +
"\t\t 4 利率\n" +
"\t\t 5 退出" );
choise = Integer.parseInt( inputChoise ); 
switch( choise )
{
case 1 :
cash= cash + cash * rate;
JOptionPane.showMessageDialog( null,"您的余额: " + cash );
break;
case 2 : 
String in = 
JOptionPane.showInputDialog( "请在空白框内输入金额!\n"+
"您要存款的金额是:" );
money = Integer.parseInt( in );
if((money>0)&&(money%100==0))
{
cash=cash+money;
JOptionPane.showMessageDialog(null,"存款成功!!");
JOptionPane.showMessageDialog(null,"您的余额是:"+cash);
	}
else
	JOptionPane.showMessageDialog(null,"您的输入金额非法!请重输-->>>");	
try   { 
	  FileWriter   fw   =   new   FileWriter( "d:\\atm.txt ",true); 
	  PrintWriter   out   =   new   PrintWriter(fw); 
	  out.println("存款: "+money); 
	  out.close(); 
	  fw.close(); 
	  }  
 catch   (IOException   e)   { 
	  System.out.println( "Write   file   error! "); 
	  e.printStackTrace(); 
	  } 
break;
case 3 : 
String out = 
JOptionPane.showInputDialog( "请在空白框内输入金额!\n"+
"您要取款的金额是:" );
money = Integer.parseInt( out );
if((money>0)&&(money%100==0))
{
cash=cash-money;
JOptionPane.showMessageDialog(null,"取款成功!!");
JOptionPane.showMessageDialog(null,"您的余额是:"+cash);
JOptionPane.showMessageDialog(null,"请取回卡!");
	}

if((money%100==0)&&(money<=5000)&&(money>=0))
            {
            cash = cash - money;
            JOptionPane.showMessageDialog(null,"您的余额是:"+cash);
            if(money>0) 
            JOptionPane.showMessageDialog(null,"请取回现金!");
            }
            else{
            JOptionPane.showMessageDialog(null,"您的输入金额非法!请重输-->>>");
            str3= 
            JOptionPane.showInputDialog("请输入金额:"+"\n");//读入数据
            money=Integer.parseInt(str3); 
              if((money%100==0)&&(money<=5000)&&(money>=0))
            {
            cash=cash-money;            
            JOptionPane.showMessageDialog(null,"您的余额是:"+cash);
            if(money>0)
            JOptionPane.showMessageDialog(null,"请取回现金!");
            }
            else{
            JOptionPane.showMessageDialog(null,"卡被吞!");
             try{
            	Thread.sleep(2000);
            	}
             catch(InterruptedException ie){
            		System.err.println("Thread error:"+ie);
            	}
            }
            }
try   { 
	  FileWriter   fw   =   new   FileWriter( "d:\\atm.txt ",true); 
	  PrintWriter   ou   =   new   PrintWriter(fw); 
	  ou.println("取款: "+money); 
	  ou.close(); 
	  fw.close(); 
	  }  
 catch   (IOException   e)   { 
	  System.out.println( "Write   file   error! "); 
	  e.printStackTrace(); 
	  }        
break;
case 4 : 
JOptionPane.showMessageDialog(null,"您的利率是:  " + rate);
break;
case 5 :
JOptionPane.showMessageDialog( null, "谢谢使用!" ); 
System.exit(0);
}
}
}
while( choise<1 || choise>5 );
}
System.exit(0);
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值