| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 426 人关注过本帖
标题:求为ATM增加新特性和修正bug
只看楼主 加入收藏
best_1
Rank: 2
等 级:论坛游民
威 望:1
帖 子:15
专家分:16
注 册:2012-8-14
收藏
 问题点数:0 回复次数:0 
求为ATM增加新特性和修正bug
我初学Java3个月写的ATM自动提款机的代码,希望高手和大家帮帮忙增加一些新的特新import *;
import java.util.Calendar;

public class ATM {

    /**
     * @param args
     * @throws IOException
     */
    static int ch;
    static String oldPassword = "123456";// 定义一个用户的账户密码
    static String inputPassword;// 输入密码
    static String newPassword1;// 新密码1
    static String newPassword2;// 新密码2
    static double balance = 4000.0;// 余额

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // 创建缓冲输入流对象
        // br ·

        // 输入密码的错误不能超过5次,用循环实现
        for (int i = 0; i < 5; i++) {

            System.out.println("请输入密码");
            inputPassword = br.readLine();
            // 验证密码的合法性
            if (inputPassword.equals("123456")) {
                break;// 验证成功 ,退出循环
            } else {
                if (i == 4) {

                    System.out.println("累计密码错误达5次,退出系统!");
                    System.exit(0);// 累计密码错误达5次,退出系统!
                }

            }

        }

        System.out.println("登陆成功!");
        showTime();
        System.out.println("欢迎使用ATM自动取款机!");
        do {// 显示功能呢菜单
            displayMenu();

            chooseMenu();

        } while (ch != 6);

    }

    // 显示菜单方法
    static void displayMenu() {
        System.out.println();
        System.out.println("===================");
        System.out.println();
        System.out.println("1.提取现金");
        System.out.println("2.查询余额");
        System.out.println("3.修改密码");
        System.out.println("4.转账业务");
        System.out.println("5.存款");
        System.out.println("6.退出系统");
        System.out.println();
        System.out.println("===================");
        System.out.println("请选择服务项");
    }

   
    // 选择服务项
    static void chooseMenu() throws IOException {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // 创建缓冲输入流对象
                    
            String outMoneyss = br.readLine();
            int ch = Integer.parseInt(outMoneyss);
            switch (ch) {
            case 1: {
                System.out.println("进入提取现金操作");
                getMoeny();
                break;
            }
            case 2: {
                System.out.println("进入查询余额操作");
                System.out.println("您目前的存款余额为:" + balance + "元");
                break;
            }
            case 3: {
                System.out.println("进入修改密码操作");
                modPassword();
                break;
            }
            case 4: {
                System.out.println("进入转账业务操作");
                outMoneyy();

                break;
            }
            case 5: {
                System.out.println("存款操作");
            }putMeoney ();
            case 6:{   
                System.out.println("退出系统");
                break;
            }
            default:
                System.out.println("只能输入单个字符!请重新输入!");
                break;
            }
        } catch (NumberFormatException r) {
            System.out.println("只能输入数字"); // 如果输入的是数字之外的字符 ,给出提示
        }
    }

    // 显示时间
    // 5~8点显示“早上好” 9-10显示“上午好” 12-13点显示“中午好” 19-4点显示“晚上好”
    static void showTime() {
        Calendar c = Calendar.getInstance();
        int h;
        h = c.get(Calendar.HOUR_OF_DAY);
        switch (h) {
        case 5:
        case 6:
        case 7:
        case 8:
            System.out.println("早上好!");
            break;
        case 9:
        case 10:
        case 11:
            System.out.println("上午好!");
            break;
        case 12:
        case 13:
            System.out.println("中午好!");
            break;
        case 14:
        case 15:
        case 17:
        case 18:
            System.out.println("下午好!");
            break;
        case 19:
        case 20:
        case 21:
        case 22:
        case 23:
        case 24:
        case 1:
        case 2:
        case 3:
        case 4:
            System.out.println("晚上好!");
            break;
        }
    }

    // 修改密码
    public static String getInputWord() {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // 创建缓冲输入流对象
        // br ·
        String inputPwd = null;
        try {
            inputPwd = (String) br.readLine();
        } catch (IOException e) { // 接收用户的输入的字符串
            e.printStackTrace();
        }
        return inputPwd;
    }

    // 判断输入密码与原密码是否相等

    static void oldpassWord() {
        System.out.println("请输入原密码");
        inputPassword = getInputWord();
        while (!oldPassword.equals(inputPassword)) {
            System.out.println("密码不正确,请重新输入:");
            inputPassword = getInputWord();
        }
        System.out.println("原密码输入正确");

    }

    // 新密码输入功能,第一次密码输入密码,第二次输入新密码,检查两次输入新密码是否相等且密码长度是否为六位,直到正确为止
    static void newPassword() {

        System.out.println("请输入新密码:");
        newPassword1 = getInputWord();
        System.out.println("请第二次输入新密码:");
        newPassword2 = getInputWord();
        while (!newPassword1.equals(newPassword2) || newPassword1.length() != 6) {
            if (newPassword1.length() != 6) {
                System.out.println("密码长度不对,要求6位!请重新输入:");
            } else {
                System.out.println("两次输入的密码不一致,请重新输入:");
            }
            System.out.println("请输入新密码:");
            newPassword1 = getInputWord();
            System.out.println("请第二次输入新密码:");
            newPassword2 = getInputWord();
        }
    }

    // 密码修改的实现 调用 oldpassWord()方法,调用 newPassword1()方法方法进行验证
    public static void modPassword() {
        oldpassWord();// 调用 oldpassWord()方法
        newPassword(); // 调用 newPassword()方法
        oldPassword = newPassword2;// 修改密码
        System.out.println("密码修改成功");
        System.out.println("您目前的密码为:" + newPassword2);

    }

    // 取款 功能的实现
    static void getMoeny() {

        int withdrawMoeny;// 定义一个变量withdrawMoney作为取款项目
        String infos[] = { "一次只能取2000", "余额不足", "只能取50的整数倍", "输入的格式不正确","取款成功,您目前的存款余额为:" };
        // 定义一个变量withdrawMoney作为取款项目
        System.out.println("请输入取款的金额:");
        try { // 调用getInputWord()方法获得输入金额,然后转化成数字赋值给
            withdrawMoeny = Integer.parseInt(getInputWord());
            if (withdrawMoeny > balance) {// 验证金额是否大于余额
                System.out.println(infos[1]);

            } else if (withdrawMoeny > 2000) {// 验证取款金额是否大于2000
                System.out.println(infos[0]);
            } else if ((withdrawMoeny % 50) != 0) {// 验证金额是否是50的整数倍
                System.out.println(infos[2]);
            } else {
                balance = balance - withdrawMoeny;// 显示余额
                System.out.println(infos[4] + balance);
            }
        } catch (NumberFormatException r) {// 异常处理
            System.out.println(infos[3]);
        }
    }

    // 实现转账功能
    static void outMoneyy() throws IOException {
        int outMoney = 0;// 转账金额
        String infos[] = { "一次只能转账2000", "余额不足", "只能转账50的整数倍", "输入的格式不正确","取款成功,您目前的存款余额为:" };
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            System.out.println("请输入转入的账号:");

            String inAccount = "";// 转入账号

            inAccount = br.readLine();
            if (inAccount.length() != 16) {// 账号必须是16位数
                System.out.println("账号必须是16位数");
                return;
            }
            long outmm = Long.parseLong(inAccount);
        } catch (NumberFormatException e) { // 判断账号输入是不是只有数字
            System.out.println("输入非法字符,必须全是数字!");
            return;
        }
        try {
            // 输入转账金额
            System.out.println("请输入转账金额");
            String outMoneyss = br.readLine();
            outMoney = Integer.parseInt(outMoneyss);
            if (outMoney > balance) {// 验证转账金额是否大于余额
                System.out.println(infos[1]);
            } else if (outMoney > 2000) {// 验证转账金额是否大于2000
                System.out.println(infos[0]);
            } else if ((outMoney % 50) != 0) {// 验证转账金额是否是50的整数倍
                System.out.println(infos[2]);
            } else {
                balance = balance - outMoney;// 显示余额
                System.out.println(infos[4] + balance);
            }
        } catch (NumberFormatException r) {
            System.out.println(infos[3]);
        }
    }
    //存款功能
    static void putMeoney () throws IOException{
//        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // 创建缓冲输入流对象
        System.out.println("请输入存款金额");
        String intMoneyss = br.readLine();
        int intMoney = Integer.parseInt(intMoneyss);
        balance=balance+intMoney;
        System.out.println("您目前的余额为:"+balance);
    }
}



搜索更多相关主题的帖子: balance 输入密码 public double import 
2012-08-15 20:27
快速回复:求为ATM增加新特性和修正bug
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.058822 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved