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機了^_^

您可能感興趣的文章:

JAVA實現簡單系統登陸註冊模組圖書管理系統java版Java Mysql學生管理系統原始碼使用Java編寫一個簡單的Web的監控系統一個簡陋的java圖書管理系統簡單實現Java版學生管理系統Java 模擬銀行自助終端系統java聯絡人管理系統簡單設計java學生資訊管理系統設計Java實現排球比賽計分系統