ATM system

Write an ATM system (the account number and password are defined by yourself, the transfer account is defined by yourself, the time can not be displayed, and the method is implemented) The effect is shown in the figure:


Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

package Bank;
/**
 * @Author: AxinGzZz
 * @Date: 2021/1/16 18:46
 */
public class Account {
    
    
    //账户账号
    //账户密码
    //余额
     private String id = "lx";
     private String id2 = "yy";
     private String password = "123456";
     private double balance = 500;
     private double balance1 = 700;
     int j =4;
     //登录入口及功能实现
     public void regist(){
    
    }
    //查询余额功能
    public void baquiry(){
    
    }
    //存款功能
    public void deposit(){
    
    }
    //取款功能
    public void withdrawal(){
    
    }
    //转账功能
    public void transferAccounts(){
    
    }
    //修改密码
    public void changePassword(){
    
    }
    //退出
    public void exit(){
    
    }

    //get,set方法访问封装数据
    public String getId() {
    
    
        return id;
    }

    public void setId(String id) {
    
    
        this.id = id;
    }

    public String getPassword() {
    
    
        return password;
    }

    public void setPassword(String password) {
    
    
        this.password = password;
    }

    public double getBalance() {
    
    
        return balance;
    }

    public void setBalance(double balance) {
    
    
        this.balance = balance;
    }

    public String getId2() {
    
    
        return id2;
    }

    public void setId2(String id2) {
    
    
        this.id2 = id2;
    }

    public double getBalance1() {
    
    
        return balance1;
    }

    public void setBalance1(double balance1) {
    
    
        this.balance1 = balance1;
    }

    //有参构造方法
    public Account(String id, String password, double balance ,double balance1) {
    
    
        this.id = id;
        this.password = password;
        this.balance = balance;
        this.balance1 = balance1;
    }

    //无参构造方法
    public Account() {
    
    
    }

    //重写toString
    @Override
    public String toString() {
    
    
        return "Account{" +
                "id='" + id + '\'' +
                ", password='" + password + '\'' +
                ", balance=" + balance +
                '}';
    }
}
package Bank;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Scanner;
/**
 * @Author: AxinGzZz
 * @Date: 2021/1/16 22:49
 */
public class AtmDemo extends Account {
    
    
    @Override
    public void regist() {
    
    
        LocalDate localDate = LocalDate.now();
        //获取年份
        int year = localDate.getYear();
        //获取月
        int month = localDate.getMonthValue();
        //获取日
        int day = localDate.getDayOfMonth();
        Calendar calendar =  Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        //获取分钟
        int minute = calendar.get(Calendar.MINUTE);
        //获取秒
        int second = calendar.get(Calendar.SECOND);
        System.out.println("----------------------");
        System.out.println("####欢迎来到实训银行####");
        System.out.println("####请按照功能菜单进行操作####");
        System.out.println("请输入您的账号:");
        Scanner scanner = new Scanner(System.in);
        String id1 = scanner.next();
        System.out.println("请输入您的密码:");
        String password1 = scanner.next();
        if (getId().equals(id1) && getPassword().equals(password1)) {
    
    
            System.out.println("登录成功! 当前余额" + getBalance() + "元"+"   "+"登录时间:"+year+"-"+month+"-"+day+":"+hour+":"+minute+":"+second);
            while (true) {
    
    
                System.out.println("-----------------------");
                System.out.println("####请按照菜单选择功能####");
                System.out.println("————————————————————————");
                System.out.println("1.余额查询 2.存款 3.取款 4.转账 5.修改密码 0.退出");
                Scanner scanner1 = new Scanner(System.in);
                int input = scanner1.nextInt();
                switch (input) {
    
    
                    case 1:
                        baquiry();
                        break;
                    case 2:
                        deposit();
                        break;
                    case 3:
                        withdrawal();
                        break;
                    case 4:
                        transferAccounts();
                        break;
                    case 5:
                        changePassword();
                        break;
                    case 0:
                        exit();
                        break;
                }
            }
        } else {
    
    
            System.out.println("账户名称或密码不对,请你重新输入,你还剩" + j + "次机会");
            j--;
            if (j < 0) {
    
    
                System.out.println("账户名称或密码情况,您已经输错5次了。请联系银行工作人员");
                scanner.close();
            } else {
    
    
                regist();
            }
        }
    }

    //重写查询余额方法
    @Override
    public void baquiry() {
    
    
        System.out.println("当前的余额为:");
        System.out.println(getBalance() + "元");
    }

    //重写存款方法
    @Override
    public void deposit() {
    
    
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入存款金额:");
        double dep = scanner.nextInt();
        if (dep % 100 != 0) {
    
    
            System.out.println("存款必须是100的倍数");
        } else {
    
    
            //计算存款金额
            dep += getBalance();
            //利用set方法更新余额
            setBalance(dep);
            System.out.println("存款成功,账户余额为:" + dep + "元");
        }
    }

    //重写取款方法
    @Override
    public void withdrawal() {
    
    
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入取款金额:");
        double dra = scanner.nextInt();
        if (dra % 100 != 0) {
    
    
            System.out.println("取款必须是100的倍数");
        } else {
    
    
            //判断取款是否大与余额
            if (dra > getBalance()) {
    
    
                System.out.println("你的余额不足");
            } else {
    
    
                //利用set方法更新余额
                dra = getBalance() - dra;
                setBalance(dra);
                System.out.println("取款成功,账户余额为::" + dra + "元");
            }
        }
    }

    //重写转账方法
    @Override
    public void transferAccounts() {
    
    
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入转账账户:");
        String trAcc = scanner.next();
        if (trAcc.equals(getId2())) {
    
    
            System.out.println("请输入转账金额:");
            Scanner scanner1 = new Scanner(System.in);
            int sum = scanner1.nextInt();
            //判断转账金额是否大于存款
            if (sum % 100 == 0 && sum < getBalance()) {
    
    
                double sum0 = getBalance() - sum;
                //利用set方法更新自己账户余额
                setBalance(sum0);
                double sum1 = sum;
                sum1 += getBalance1();
                //利用set方法更新对方账户余额
                setBalance1(sum1);
                System.out.println("转账成功,账户余额为:" + sum0 + "对方账户余额为:" + sum1);
            } else {
    
    
                System.out.println("您的余额不足");
            }
        } else {
    
    
            System.out.println("您输入的账户不存在");
        }
    }

    //重写修改密码方法
    @Override
    public void changePassword() {
    
    
        System.out.println("请输入当前密码:");
        Scanner scanner = new Scanner(System.in);
        String cp = scanner.next();
        if (cp.equals(getPassword())) {
    
    
            Scanner scanner2 = new Scanner(System.in);
            System.out.println("请输入新密码:");
            String cp2 = scanner2.next();
            System.out.println("请再次输入新密码:");
            ;
            Scanner scanner1 = new Scanner(System.in);
            String cp1 = scanner1.next();
            if (cp1.equals(cp2)) {
    
    
                cp = cp1;
                setPassword(cp);
                System.out.println("修改密码成功,请重新登录");
                regist();
            } else {
    
    
                System.out.println("您输入的密码不一致!");
                changePassword();
            }
        } else {
    
    
            System.out.println("您当前输入的密码不对");
        }
    }

    //重写退出方法
    @Override
    public void exit() {
    
    
        System.out.println("您确定要退出系统?是则按Y,否则按N");
        Scanner scanner = new Scanner(System.in);
        String input = scanner.next();
        String input1 = "Y";
        if (input.equals(input1)) {
    
    
            System.out.println("您已退出系统,是否再次登录?是则按Y,否则按N");
            Scanner scanner1 = new Scanner(System.in);
            String input2 = scanner1.next();
            String input3 = "Y";
            if (input2.equals(input3)) {
    
    
                regist();
            } else {
    
    
                System.out.println("您已退出系统!");
                System.exit(0);
            }
        }
    }
}
package Bank;


/**
 * @Author: AxinGzZz
 * @Date: 2021/1/16 19:32
 */
public class BankDemo {
    
    
    public static void main(String[] args) {
    
    
        Account  account = new AtmDemo();
        account.regist();

    }
}

Effect picture
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44193337/article/details/112741795