关于#java#的问题:正在用java写ATM为什么能运行 但是注册完账户之后再登录 集合中的账户提取不出来或者没存进去

求!正在用java写ATM
为什么能运行 但是注册完账户之后再登录 集合中的账户提取不出来或者没存进去


import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class ATMSystem {
    public static void main(String[] args) {
        // 1.定义类
        // 2.定义一个集合 方便以后存储账户信息
        ArrayList accounts = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        // 3.展示系统首页
        while (true) {
            System.out.println("=============琛琛ATM系统==============");
            System.out.println("1.账户登录");
            System.out.println("2.账户开户");

            int command = sc.nextInt();

            switch (command) {
                case 1 :
                    // 账户登录
                    login(accounts, sc);
                    break;
                case 2 :
                    // 账户开户
                    register(accounts,sc);
                    break;
                default:
                    System.out.println("您的输入的命令不正确~~~~~");
            }
        }

    }

    private static void login(ArrayList accounts, Scanner sc) {
        System.out.println("=============系统登录操作============");
        // 判断当前的集合中有无账户
        Account account = new Account();
        if (accounts.size() == 0) {
            System.out.println("当前的系统中不存在账户,请你先注册账户");
            return;
        }
        // 集合中存在账户 下面开始登录
        while (true) {
            System.out.println("请输入您的卡号");
            String cardID = sc.next();

            Account acc = getAccountByCardID(cardID, accounts);
            if (acc != null) {
                while (true) {
                    System.out.println("请输入密码");
                    String password = sc.next();
                    if (acc.getCardID().equals(password)) {
                        System.out.println("恭喜您登陆成功" + acc.getUserName() + "先生/女士,您的卡号是" + acc.getCardID());
                        break;
                    } else {
                        System.out.println("对不起,您输入的密码有误~~");
                    }
                }
            } else {
                System.out.println("对不起,系统中不存在该卡号");
            }
        }
    }

    private static void register(ArrayList accounts, Scanner sc) {
        Account account = new Account();
        System.out.println("==============账户开户操作==============");

        System.out.println("请输入您的用户名");
        String userName = sc.next();
        account.setUserName(userName);

        while (true) {
            System.out.println("请输入您的密码");
            String password = sc.next();
            System.out.println("请确认你您的密码");
            String okPassword = sc.next();

            if (password.equals(okPassword)) {
                    account.setUserPassword(okPassword);
                    break;
            } else {
                System.out.println("您两次输入的密码不一致~~请重新输入");
            }
        }

        System.out.println("请您输入当前用户的限额");
        double quotaMoney = sc.nextDouble();
        account.setQuotaMoney(quotaMoney);

        // 用户ID

        String cardID = getRandomCardID(accounts);
        account.setCardID(cardID);

        // 把账户对象添加的集合当中
        accounts.add(account);
        System.out.println("恭喜您开户成功," + account.getUserName() + "先生/女士,您的卡号是 :" + account.getCardID());
    }

    /**
     * 得到一个随机ID
     * @param accounts
     * @return 将得到的不重复的ID返回
     */
    private static String getRandomCardID(ArrayList accounts) {
        Random r = new Random();
        while (true) {
            String cardID = "";
            int a;
            for (int i = 0; i < 8; i++) {
                a = r.nextInt(10);
                cardID += a;
            }
            // 判断这个ID是否重复
            Account acc = getAccountByCardID(cardID,accounts);
            if (acc == null) {
                return cardID;
            }
        }
    }

    /**
     * 查询ID
     * @param cardID
     * @param accounts
     * @return 如果返回null 则该ID不存在 如果返回八位ID 则存在该ID
     */
    private static Account getAccountByCardID(String cardID,ArrayList accounts) {
        for (int i = 0; i < accounts.size(); i++) {
            Account acc = accounts.get(i);
            if (acc.equals(cardID)) {
                return acc;
            }
        }
        return null;
    }

}

你根据账户id获取账号的方法里面,那个判断写错了,你用账户和id去equal,这必然不会成立啊