⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atm.java

📁 本程序实现了银行取款机的模拟,分别设置了取款,存款,修改密码等功能.
💻 JAVA
字号:
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;  
/**********实现具体取款机功能*********/
class ATM {
     
     Account act;
 
 public ATM() 
{
   act=new Account("000000","Devil","123456",50000);
}

/***********欢迎界面***********/
protected void Welcome()
{
int num;
//String inputnum;
String inputnum="---------------------------------\n";
       inputnum +="\n" +"Welcome to use ATM !.\n" +"\n";
       inputnum+=" 1.>take money." +"\n" +" 2.>information query." +"\n" +" 3.>password set." +"\n" +" 4.>exit." +"\n";
   
      //JOptionPane.showMessageDialog( null, str );
      inputnum= JOptionPane.showInputDialog( inputnum); 
     num=Integer.parseInt(inputnum);
}

/**********登陆系统**********/
protected void Load_Sys() throws Exception
{
   //Welcome();
   String cardid,pwd;
  // String inputcard,inputpwd;
   int counter=0;

   BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
   
do 
{
   cardid= JOptionPane.showInputDialog( "please input your card id:" );
   //card=String.parseString( inputcard ); 
   pwd = JOptionPane.showInputDialog( "please inpu your password" );
   //pwd=String.parseString( inputpwd ); 
   //*System.out.println("请输入您的信用卡号:");
   cardid=buf.readLine();
   pwd = JOptionPane.showInputDialog( "please inpu your password" );
   //System.out.println("请输入您的密码:");
   pwd=buf.readLine();
   
if(!isRight(cardid,pwd))
{
  JOptionPane.showMessageDialog( null, "your card id or your password may be wrong" );
  //System.out.println("您的卡号或密码输入有误.");
  counter ++;
}
else
  SysOpter();

}while(counter<3);
Lock_Sys();
}

/**********系统操作**********/
protected void SysOpter() throws Exception
{
    int num;
    Welcome();
    //String inputnum;
    //inputnum = JOptionPane.showInputDialog( "please enter the number represent the operation betwwen 1 and 4:" );
    BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
    //JOptionPane.showMessageDialog( null, "please enter the number represent the operation betwwen 1 and 4:" );
    //System.out.println("请选择您要操作的项目(1-4):");
    //num=Integer.parseInt( inputnum); 
    num=buf.read(); //num为ASICC码转换的整数
    switch(num) {
    case 49: BetBalance();   break;
    case 50: Inqu_Info();    break;
    case 51: Set_Password(); break;
    case 52: Exit_Sys();     break;
}
System.exit(1);
}

/**********信息查询**********/
protected void Inqu_Info() 
{
     String output;
     output="---------------------\n" +
     act.get_Code() +"\n" + 
     act.get_Name() +"\n" +
     act.get_Money() +"\n" +
     "-----------------------";
     JOptionPane.showMessageDialog( null, output );
     /*System.out.print("---------------------\n" +
     act.get_Code() +"\n" + 
     act.get_Name() +"\n" +
     act.get_Money() +"\n" +
     "-----------------------");*/
}

/**********取款**********/
public void BetBalance() throws Exception
{
    
     String str=null,str1;
     BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
        JOptionPane.showMessageDialog(null, "enter the amount!");
   do {
         JOptionPane.showMessageDialog(null, "enter the amount!");//有问题
         //System.out.println("请输入您要取的数目:");
         str=buf.readLine();
         str1=String.valueOf(act.get_Money());
            if(str.compareTo(str1)>0)
             {
          JOptionPane.showMessageDialog(null, "beyond your store,please try again!");
          //System.out.println("超过已有的钱数,请重新输入您要取的数目:");
       }
     else 
     {
     /*操作成功*/
      // act.set_Balance(str);
      JOptionPane.showMessageDialog(null, "done,please take away your money!");
     //System.out.println("取款成功,请收好您的钱.");
     Welcome();
     SysOpter();
   }
     }while(true);


}

/**********判断卡内是否有钱**********/
protected boolean isBalance()
 {
         if(act.get_Money()<0) 
         { 
           JOptionPane.showMessageDialog(null, "sorry,you can't take so much!");
           //System.out.println("对不起,您的钱数不够或卡已透支.");
           return false;
          }
        return true;
}

/********卡号密码是否正确******/
protected boolean isRight(String card,String pwd)
{
    if(act.get_Code().equals(card) && act.get_Password().equals(pwd))
    return true;
    else
    return false;
}

/**********密码修改**********/
protected void Set_Password() throws Exception
{
         String pwd=null;
        // String password;
         int counter=0;
         //JOptionPane.showInputDialog("");
         BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
      do {
          JOptionPane.showMessageDialog(null, "please input your previouspassword!");
          //System.out.println("请输入旧密码:");
          //password=JOptionPane.showInputDialog("input password");
          //pwd=JOptionPane.showInputDialog(passwod);
          pwd=buf.readLine();
        if(act.get_Password().equals(pwd))
            {
             do {
                   JOptionPane.showMessageDialog(null, "please input your password!");
                   //System.out.println("请输入新密码:");
                   String pwd1=buf.readLine();
                   JOptionPane.showMessageDialog(null, "please input again!");
                   //System.out.println("请再次输入新密码:");
                   String pwd2=buf.readLine(); 
                   if(!pwd1.equals(pwd2))
                   {
                   JOptionPane.showMessageDialog(null, "not equal,try again!");
                   //System.out.println("两次输入不一致,请再次输入.");
                   }
                   else
                  {
                   JOptionPane.showMessageDialog(null, "congratulations to you!");
                   //System.out.println("密码修改成功,请使用新密码.");
                   Welcome();
                   SysOpter();
                   }
              }while(true);
           }
         }while(counter>3);

}

/**********锁定机器**********/
protected void Lock_Sys() 
{
	         JOptionPane.showMessageDialog(null, "sorry ,something wrong with your operation,your card is handed in!");
          //System.out.println("对不起,您的操作有误,卡已被没收.");
          System.exit(1);
}

/**********结束系统**********/
protected void Exit_Sys() 
{
        JOptionPane.showMessageDialog(null, "thanks for your using,goodbye !");
        //System.out.println("感谢您使用本系统,欢迎下次在来,再见!");
        System.exit(1);
}

}
/*******************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -