亲宝软件园·资讯

展开

java编写简单的ATM存取系统 java编写简单的ATM存取系统

人气:0
想了解java编写简单的ATM存取系统的相关内容吗,在本文为您仔细讲解java编写简单的ATM存取系统的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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机了^_^

加载全部内容

相关教程
猜你喜欢
用户评论