其他分享
首页 > 其他分享> > ATM机案例3之菜单操作类(五)

ATM机案例3之菜单操作类(五)

作者:互联网

ATM机案例3之菜单操作类(五)

所有目录
image

Application(菜单操作类)

点击查看代码
import java.util.Scanner;

public class Application {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        systemMenu(scanner);
    }


    //系统菜单界面
    public static void systemMenu(Scanner scanner) {
        System.out.println("欢迎使用ATM机:\n1、登录\t2、注册\t0、退出");
        int choose = scanner.nextInt();
        switch (choose) {
            case 0:
                System.out.println("退出成功!");
                break;
            case 1:
                login(scanner);
                break;
            case 2:
                register(scanner);
                break;
            default:
                System.out.println("非法输入,请重试!");
                systemMenu(scanner);
        }
    }

    public static void login(Scanner scanner) {
        //1、登陆
        AccountDAO accountDAO = new AccountDAO();

        System.out.println("请输入账号id:");
        int accountid = scanner.nextInt();
        System.out.println("请输入账号密码:");
        String accountpassword = scanner.next();

        if (accountDAO.login(accountid, accountpassword)) {
            mainMenu(scanner,accountid);
        } else {
            System.out.println("登录失败!\n请检查账号和密码!");
            systemMenu(scanner);
        }
    }

    public static void register(Scanner scanner) {
        //2、注册
        AccountDAO accountDAO = new AccountDAO();
        System.out.println("请设置账号id:");
        int userid = scanner.nextInt();
        if (accountDAO.judgeIsNull(userid)) {
            System.out.println("请设置账号用户名:");
            String username = scanner.next();
            System.out.println("请设置账号密  码:");
            String userpassword = scanner.next();
            System.out.println("请设置性  别:");
            String usergender = scanner.next();
            accountDAO.createAccount(userid,username,userpassword,usergender);
            systemMenu(scanner);
        } else {
            System.out.println("该账号id已存在!请重试");
            register(scanner);
        }
    }


    //主菜单界面,携带身份信息
    public static void mainMenu(Scanner scanner,int id) {

        ShowInfoDAO showInfoDAO = new ShowInfoDAO();
        AccountDAO accountDAO = new AccountDAO();
        CardDAO cardDAO = new CardDAO();
        System.out.println("\t\t\t主菜单:\n1、查看银行卡信息\n2、转账\n3、注销银行卡\n4、注销账户\n5、退出系统");
        int choose = scanner.nextInt();
        switch (choose) {
            case 1:
                //展示查询信息
                showInfoDAO.show(id);
                mainMenu(scanner, id);
                break;
            case 2:
                //2、转账功能
                System.out.println("请输入汇款账户:");
                int outputID = scanner.nextInt();
                if (CardDAO.judge(outputID)) {
                    System.out.println("汇款账户不存在!请重试!");
                    mainMenu(scanner, id);
                    break;
                }
                System.out.println("请输入转账金额:");
                double money = scanner.nextDouble();
                System.out.println("请输入收款账户:");
                int inputID = scanner.nextInt();
                if (CardDAO.judge(inputID)) {
                    System.out.println("收款账户不存在!请重试!");
                    mainMenu(scanner, id);
                    break;
                }
                double outBalance = CardDAO.findByNumber(outputID).getBalance();
                double inBalance = CardDAO.findByNumber(inputID).getBalance();
                cardDAO.outputMoney(money,outputID);
                cardDAO.inputMoney(money, inputID);
                System.out.printf("汇款卡号%d:\t%f¥》》》卡号%d:\t%f¥\n",outputID,outBalance,outputID,outBalance-money);
                System.out.printf("收款卡号%d:\t%f¥》》》卡号%d:\t%f¥\n",inputID,inBalance,inputID,inBalance+money);
                mainMenu(scanner,id);
                break;
            case 3:
                //3、注销银行卡
                System.out.println("请输入要删除的卡号:");
                int deleteCardNumber = scanner.nextInt();
                showInfoDAO.deleteShowInfo(deleteCardNumber);
                mainMenu(scanner,id);
                break;
            case 4:
                //4、注销账户
                System.out.println("是否确定销户?\n1、确认\t2、取消");
                int sure = scanner.nextInt();
                if (sure == 1) {
                    accountDAO.deleteAccount(id);
                    mainMenu(scanner,id);
                } else if (sure == 2) {
                    mainMenu(scanner, id);
                } else {
                    System.out.println("非法输入!请重试!");
                    mainMenu(scanner, id);
                }
                break;
            case 5:
                //5、退出系统
                systemMenu(scanner);
                break;
            default:
                System.out.println("非法输入!请重新输入!");
                mainMenu(scanner,id);
                break;
        }
    }
}

标签:菜单,scanner,ATM,System,break,案例,println,id,out
来源: https://www.cnblogs.com/black-jay-blogs/p/15585614.html