JAVA项目----ATM的实现功能

ATM取款机实现
(1)ATM客户端需要登陆,用户输入正确的银行卡号和密码,系统核对无误后才能进行操作
(2)登陆后,用户可以进行查询余额、取款、和修改密码的操作;
(3)取款操作,有操作结果提示,如“操作成功”或“余额不足,操作失败”
(4)密码输入错误3次将提示“对不起,卡已经被没收”
(5)使用控制台程序完成本应用

定义三个类ATM、Input、Operation和一个测试类 Testdocuments

package com.iflytek;

public class ATM {
    private double balance;//余额
    private double money;//取钱
    private int cardsNum;//卡号
    private int passWord;//密码
    private String name;//客户姓名
    private int inputNum;//输入账户
    private int inputWord;//输入密码

    public double getBalance() {
        return balance;
    }
    public void setBalance(double balance) {
        this.balance = balance;
    }
    public double getMoney() {
        return money;
    }
    public void setMoney(double money) {
        this.money = money;
    }
    public int getCardsNum() {
        return cardsNum;
    }
    public void setCardsNum(int cardsNum) {
        this.cardsNum = cardsNum;
    }
    public int getPassWord() {
        return passWord;
    }
    public void setPassWord(int passWord) {
        this.passWord = passWord;
    }
    public int getInputNum() {
        return inputNum;
    }
    public void setInputNum(int inputNum) {
        this.inputNum = inputNum;
    }
    public int getInputWord() {
        return inputWord;
    }
    public void setInputWord(int inputWord) {
        this.inputWord = inputWord;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}   


package com.iflytek;

import java.util.Scanner;

public class Input {
    public void out(){
        System.out.println("------------------------------");
        System.out.println("欢迎使用模拟自动取款机程序.");
        System.out.println("------------------------------");
        System.out.println("1.>取款.\n2.>查询信息.\n3.密码设置.\n4.退出系统.");
    }   
    public boolean input(int card, int password){

        for (int i = 0; i < 3; i++) {
            System.out.println("请输入您的信用卡号:");
            Scanner sc1 = new Scanner(System.in); // 输入卡号
            int inputCard = sc1.nextInt();
            System.out.println("请输入您的密码:");
            Scanner sc2 = new Scanner(System.in);  //输入密码
            int inputWord = sc2.nextInt();

            if (card == inputCard && password == inputWord) {
                return true;
            }else {
                if (i == 2) {
                    System.out.println("对不起,输入错误已达三次,您的卡已经被没收");
                }else {
                    System.out.println("您的卡号或密码输入有误.");
                }
            }
        }        
        return false;
    }
}


package com.iflytek;

import java.util.Scanner;

public class Operation {
    Input input = new Input();

    public void choose(ATM atm) {
        input.out();
        System.out.println("请选择您要操作的项目(1-4):");
        Scanner sc1 = new Scanner(System.in); 
        int num = sc1.nextInt();
        switch (num) {
        case 1:
            getMoney(atm);
            break;
        case 2:
            query(atm);
            break;
        case 3:
            setPasswrod(atm);
            break;
        case 4:
            exit();
            break;
        default:
            error();
            break;
        }
    }
    public boolean getMoney(ATM atm){
//      input.out();
        System.out.println("请输入您要取的数目:");
        for(int i= 0;i<3;i++){
            Scanner sc = new Scanner(System.in);
            atm.setMoney(sc.nextInt()); 
            if(atm.getMoney() > atm.getBalance()){
                System.out.println("超过已有的钱数,请重新输入您要取的数目:");

            }else{
                atm.setBalance(atm.getBalance()-atm.getMoney());
                System.out.println("取款成功,请收好您的钱");
                return true;
            }
        }
        return false;
    }

    public void query(ATM atm){
        System.out.println("客户账号:"+atm.getCardsNum());
        System.out.println("客户名:"+atm.getName());
        System.out.println("客户账户余额:"+atm.getBalance());
    }

    public void setPasswrod(ATM atm){
        System.out.println("请重新输入密码:");
        Scanner sc1 = new Scanner(System.in); 
        int num = sc1.nextInt();
        atm.setPassWord(num);
        System.out.println("您的密码为:"+"\n"+atm.getPassWord());
    }

    public void exit(){

        System.out.println("感谢您使用本系统,欢迎下次再来,再见!");
        System.exit(0);
    }

    public void error(){
        //shurude shuju
        System.out.println("输入的数据有误");
    }
}


package com.iflytek;

public class Testdocumets {

    public static void main(String[] args) {
        ATM atm = new ATM();
        atm.setBalance(2000);
        atm.setCardsNum(10086);
        atm.setPassWord(10086);
        atm.setName("ssss");

        Input input = new Input();
        input.out();
        boolean result = input.input(atm.getCardsNum(), atm.getPassWord());

        Operation operation = new Operation();
        if (result) {
            operation.choose(atm);
        }
    }
}

JAVA项目----ATM的实现功能_第1张图片
JAVA项目----ATM的实现功能_第2张图片

JAVA项目----ATM的实现功能_第3张图片

JAVA项目----ATM的实现功能_第4张图片

JAVA项目----ATM的实现功能_第5张图片

JAVA项目----ATM的实现功能_第6张图片

你可能感兴趣的:(JAVA项目----ATM的实现功能)