?? atm.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 + -