程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> java編寫簡略的ATM存取體系

java編寫簡略的ATM存取體系

編輯:關於JAVA

java編寫簡略的ATM存取體系。本站提示廣大學習愛好者:(java編寫簡略的ATM存取體系)文章只能為提供參考,不一定能成為您想要的結果。以下是java編寫簡略的ATM存取體系正文


老手練手必備~

暗碼賬戶為:

先創立賬戶類:


package cn.Atm;
/**
* @author 偶my耶
*/
import java.io.*;
import com.project.project;
public class Account {
  private String number=null;
  private String name=null;
  private String password=null;
  private double money=0.0;
  public Account(String number,String name,String password,double money){
      this.number=number;
      this.name=name;
      this.password=password;
      this.money=money;
  }
  public String getNumber() {
      return number;
  }
  public void setNumber(String number) {
      this.number = number;
  }
  public String getName() {
      return name;
  }
  public void setName(String name) {
      this.name = name;
  }
  public String getPassword() {
      return password;
  }
  public void setPassword(String password) {
      this.password = password;
  }
  public double getMoney() {
      return money;
  }
  public void setMoney(double money) {
      this.money = money;
  }
  protected void  sub_Balance(double mon) {
      money-=mon;   
  }
  protected void add_Balancen(double mon) {
      money+=mon;   
  }
}

然後樹立操作類:

外面包括各類操作辦法:


package cn.Atm;
/**
 * @author 偶my耶
 */
import java.io.*;

import com.project.project;
public class ATM {
    Account act;

    public ATM(){
    act=new Account("0000", "test", "0000", 2000);
    }
    /*************迎接界面*********************/
    protected void Welcome(){
        String str="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
        System.out.print(str+"\n");
        System.out.print(
                "1.取款"+"\n"+
                "2.查詢"+"\n"+
                "3.存款"+"\n"+
                "4.加入"+"\n"
                );
    System.out.print(str+"\n");
    }
    /************上岸體系********************/
    protected void Load_Sys() throws Exception{
        String card,pwd;
        int counter=0;
        BufferedReader  br=new BufferedReader(new InputStreamReader(System.in));
        do{
            System.out.println("請輸出你的卡號");
            card=br.readLine();
            System.out.println("請輸出你的暗碼");
            pwd=br.readLine();
            if (!isRight(card,pwd)) {
                System.out.println("你的卡號或暗碼有誤");
                counter++;
            }
            else {
                Welcome();
                SysOpter();
            }
        }while(counter<5);
        System.exit(1);
    }
    /**********體系操作提醒******************/
    protected void SysOpter() throws Exception {
        int num;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("請選擇你要操作的項目(1--4)");
        num=br.read();
        switch (num) {
        case 49:
            GetBalance();
            break;
        case 50:
            Inqu_Iofo();
            break;
        case 51:
            AddBalance();
            break;
        case 52:
            Exit_Sys();
            break;
        }
    }
    /**********信息查詢*******************/
    protected void Inqu_Iofo() throws Exception{
        // TODO Auto-generated method stub
        String str="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
        System.out.print(str+"\n");
        System.out.print(
                "賬號"+act.getNumber()+"\n"+
                "姓名"+act.getName()+"\n"+
                "余額"+act.getMoney()+"\n"+
                str+"\n"
                );
    SysOpter();
    }
   
    /**********存款******************/
    public void AddBalance() throws Exception{
        // TODO Auto-generated method stub
        String str=null,str1;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        do {
            System.out.println("請輸出存款數量");
            str=br.readLine();
            double qu=Double.valueOf(str).doubleValue();
            act.add_Balancen(qu);
            System.out.println("存款勝利,你的賬戶余額為"+act.getMoney());
            Welcome();
            SysOpter();
        } while (true);
    }
    /**********取款********************/
    public void GetBalance() throws Exception{
        // TODO Auto-generated method stub
        String str=null,str1;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        do {
            System.out.println("請輸出取款數量");
            str=br.readLine();
            double qu=Double.valueOf(str).doubleValue();
            if(qu>act.getMoney()){
                System.out.println("余額缺乏請從新輸出");
            }
            else {
                act.sub_Balance(qu);
                System.out.println("取款勝利你的賬戶余額未"+act.getMoney());
                Welcome();
                SysOpter();
            }
        } while (true);
    }
    /*********加入******************/
    protected void Exit_Sys () {
        // TODO Auto-generated method stub
        System.out.println("平安加入!");
        System.exit(1);
    }
   
    /**********卡號和暗碼能否准確********************/
    protected boolean isRight (String card, String pwd) {
        // TODO Auto-generated method stub
        if (act.getNumber().equals(card)&&act.getPassword().equals(pwd)) {
            return true;
        } else {
            return false;
        }
   
    }
    public static void main(String[] args) throws Exception {
        ATM atm=new ATM();
//        atm.Welcome();
        atm.Load_Sys();
        }
}

代碼僅供參考

運轉成果以下

 

好了,小同伴們可以本身做個ATM機了^_^

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved