国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

java編寫簡單的ATM存取系統

2019-11-26 15:18:38
字體:
來源:轉載
供稿:網友

新手練手必備~

密碼賬戶為:

先創建賬戶類:

復制代碼 代碼如下:

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贵溪市| 宝兴县| 高尔夫| 通州市| 肇源县| 兴隆县| 宁夏| 罗田县| 略阳县| 昌邑市| 尼木县| 通州区| 油尖旺区| 松阳县| 勃利县| 肥东县| 白山市| 岫岩| 隆子县| 长丰县| 蓬溪县| 宝应县| 吴忠市| 沧州市| 叙永县| 新沂市| 商丘市| 尖扎县| 调兵山市| 雷州市| 普格县| 聂荣县| 绥宁县| 武夷山市| 沈丘县| 汤阴县| 万荣县| 济南市| 遂宁市| 临湘市| 尤溪县|