简单的ATM 注册,登录,存钱,取钱,管理员查看 功能的实现,register(注册方法),login(登录方法),look(管理员查看方法),并通过集合存储所有用户的信息。

1.main()方法

public class test {
    public static void main(String[] args) {

        ArrayList<people> people = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);


        while (true) {
            System.out.println("1.注册" + "\t" + " 2.登录" + "\t" + " 3.退出" + "\t" + "4.超级管员查看");
            System.out.println("------------------------------");
            System.out.println("请选择菜单:");
            int input = scanner.nextInt();
            switch (input) {
                case (1):
                    register(people);
                    break;
                case (2):
                    login(people);
                    break;
                case (3):
                    System.out.println("欢迎再次光临");
                    System.exit(0);
                    break;
                case (4):
                    System.out.println("超级管理员查看所有用户信息:");
                    look(people);
                    break;
            }
        }
    }

    public static void register(ArrayList<people> a) {
        int sum = 0;
        people people1 = new people();
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入用户名:");
        String p1 = scanner.next();
        System.out.print("请存钱数:");
        double pp1 = scanner.nextInt();
        System.out.print("请输入密码:");
        String ppp1 = scanner.next();
        people1.setName(p1);
        people1.setMoney(pp1);
        people1.setPassword(ppp1);
        a.add(people1);
        //a.add(people1);
        System.out.println("成功注册");

        for (int i = 0; i < a.size(); i++) {
            System.out.println(a.get(i).getName());
        }


    }

    public static void login(ArrayList<people> aa) {
        Scanner scanner = new Scanner(System.in);
        for (int bb = 0; bb < 3; bb++) {
            System.out.println("请输入用户名密码登录");
            System.out.print("用户名:");
            String a = scanner.next();
            System.out.print("密码:");
            String b = scanner.next();
            for (int i = 0; i < aa.size(); i++) {
                if (a.equals(aa.get(i).getName()) && b.equals(aa.get(i).getPassword())) {
                    System.out.println("欢迎进入赵一玄银行");
                    System.out.println("用户:" + a + "\t" + "存款:" + aa.get(i).getMoney());
                    System.out.println("please wo select:" + " \t " + "1:取钱");
                    int s = scanner.nextInt();
                    other:
                    while (true) {
                        if (s == 1) {
                            Scanner sc = new Scanner(System.in);
                            System.out.print("请输入取款数:");
                            int money = scanner.nextInt();
                            for (int j = 0; j < aa.size(); j++) {
                                if (a.equals(aa.get(j).getName()) && money <= aa.get(j).getMoney()) {
                                    double mm = aa.get(j).getMoney();
                                    mm -= money;
                                    aa.get(j).setMoney(mm);
                                    System.out.println("用户:" + aa.get(i).getName() + " \t存款数:" + aa.get(j).getMoney());
                                    break other;
                                } else {
                                    System.out.println("余额不足!");
                                }
                            }
                        } else {
                            System.out.println("用户名或密码错误,请重新登录");
                            break;
                        }
                    }

                } else {
                    if (i == 2) {
                        System.out.println("机会用完");
                    } else {
                        System.out.println("还剩" + (2 - i) + "次机会");
                    }

                }
            }


        }


    }

    public static void look(ArrayList<people> aa) {
        for (int l = 0; l < aa.size(); l++) {
            System.out.println("name:" + aa.get(l).getName() + "  \t money:" + aa.get(l).getMoney());
        }
    }

}

2.people对象

public class people {
    String name;
    String password;
    String birthday;



    double money;


    public Double getMoney() {
        return money;
    }

    public void setMoney(Double money) {
        this.money = money;
    }

    public String getPassword() {
        return password;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }



}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值