当前位置: 代码迷 >> Java相关 >> 写一个ATM取款机的程序~自己写的实在下不下去了!
  详细解决方案

写一个ATM取款机的程序~自己写的实在下不下去了!

热度:313   发布时间:2009-08-30 21:48:02.0
写一个ATM取款机的程序~自己写的实在下不下去了!
老师发了一个写好的.jar文件
我写了可以说是90%的程序,可是最后实在写不下去了,原因为不知道Map数据的传递问题
现在想请大虾们帮忙写个程序,让我学习一下,谢谢(这里暂时不考虑异常处理)
把这个后缀改成.jar就可以了,运行DOS,  java -jar TestBank.jar

下面是我写的程序
程序代码:
import java.util.*;
public class Test {
    public static void main(String[] args) {
        Register re = new Register();
        Enter en = new Enter();
        System.out.println("欢迎使用银行管理系统!");
        for (;;) {
            System.out.println("1.注册    2.登录    3.退出");
            Scanner sc = new Scanner(System.in);
            try {
                int i = sc.nextInt();
                switch (i) {
                case 1:
                    System.out.println("请输入要注册的银行卡种类 1 or 2 >> 1:借记卡    2:信用卡");
                    i = sc.nextInt();
                    re.register(i);
                    continue;
                case 2:
                    en.enter();
                    continue;
                case 3:
                    System.exit(0);
                default:
                    System.out.println("输入不符合要求!");
                }
            } catch (Exception e) {
                System.out.println("输入不符合要求!");
            }
        }
    }
}
程序代码:
import java.util.*;
public class Register {
    int key = 10001;
    Map m = new Map();
    public void register(int i) {
        String str = "";
        Scanner sc = new Scanner(System.in);
        if (1 == i) {
            System.out.print("您选择了借记卡,");
        }
        if (2 == i) {
            System.out.print("您选择了信用卡,");
        }
        System.out.print("请输入您的姓名:");
        String name = sc.next();
        for (;;) {
            try {
                System.out.print("请第一次输入 密码:");
                String passwd = sc.next();
                System.out.print("请第二次输入 密码:");
                String passwdch = sc.next();
                if (!(passwd.equals(passwdch))) {
                    System.out.println("两次 密码不一致,请重新输入!");
                    continue;
                }
                System.out.print("请输入 邮箱 email:");
                String email = sc.next();
                System.out.print("请输入 身份证号:");
                String identification = sc.next();
                str = "  用户名" + name + "  密码" + passwd + "  邮箱" + email
                        + "  身份证号" + identification;
                String s = "     " + name + "    " + email + "      0      ";
                if (2 == i) {
                    System.out.print("请输入此卡的透支额度:");
                    int money = sc.nextInt();
                    str = str + "  透支额度   " + money;
                    s = s + money;
                } else {
                    s = s + "0";
                }
                m.put(key, s);
                m.put(String.valueOf(key), passwd);
            } catch (Exception e) {
                System.out.println("输入不符合要求!透支额度为初始化1000。");
            }
            System.out.println("新帐户为:卡号" + key + str);
            System.out.println();
            m.get();
            key++;
            return;
        }
    }
}
程序代码:
import java.util.*;
public class Map {
    private HashMap<Integer, String> map;
    private HashMap<String, String> mappassword;
    public Map() {
        this.map = new HashMap<Integer, String>();
        this.mappassword = new HashMap<String, String>();
    }
    public void put(int key, String value) {
        this.map.put(Integer.valueOf(key), value);
    }
    public void put(String key, String value) {
        this.mappassword.put(key, value);
    }
    public void get() {
        System.out.println("-------------本行所有帐户--------------");
        System.out
                .println("id      名字          邮箱           帐户余额          透支余额");
        Set keySet = map.keySet();
        Iterator<String> it = keySet.iterator();
        while (it.hasNext()) {
            Object key = it.next();
            String val = map.get(key);
            System.out.println(key + " " + val);
        }
        System.out.println();
    }
    public String get(String s) {
        String passwd = mappassword.get(s);
        return passwd;
    }
    public void get(int i) {
        String passwd = map.get(i);
        System.out
                .println("id      名字          邮箱           帐户余额          透支余额");
        System.out.println(Integer.valueOf(i) + passwd);
    }
}
程序代码:
import java.util.*;
public class Enter {
    Map m = new Map();
    Scanner sc = new Scanner(System.in);
    public void enter() {
        for (;;) {
            System.out.println("请输入卡号:");
            String id = sc.next();
            System.out.println("请输入密码:");
            String passwd = sc.next();
            m.get(id);
            System.out.println(m.get(id));
            if (passwd.equals(m.get(id))) {
                System.out.println("登录成功!");
            } else {
                System.out.println("登录失败!");
                continue;
            }
            for (;;) {
                System.out.println("欢迎使用银行管理系统!");
                System.out.println("1:取款  2:存款   3:查询余额   4:修改密码   5:退出 ");
                int number = sc.nextInt();
                switch (number) {
                case 1:
                    qu(id);
                    continue;
                case 2:
                    cun(id);
                    continue;
                case 3:
                    chaxun(id);
                    continue;
                case 4:
                    xiugai(id);
                    continue;
                case 5:
                    System.out.println("欢迎下次登录,再见!");
                    return;
                default:
                    System.out.println("输入不符合要求!");
                }
            }
        }
    }
    public void xiugai(String id) {
        System.out.println("请输入当前密码,最多三次:");
        for (int i = 0; i < 3; i++) {
            String passwd = sc.next();
            if (passwd.equals(m.get(id))) {
                for (;;) {
                    System.out.println("请输入新密码:");
                    passwd = sc.next();
                    System.out.println("请重新输入新密码:");
                    String passwd1 = sc.next();
                    if (passwd.equals(passwd1)) {
                        m.put(id, passwd);
                        break;
                    } else {
                        System.out.println("两次输入的密码不一致!");
                        continue;
                    }
                }
            } else {
                System.out.println("错误!请重新输入密码:");
            }
        }
    }
    public void chaxun(String id) {
        m.get(id);
    }
    public void cun(String id) {
        System.out.println("请输入存款金额:");
        int money = sc.nextInt();
        // 因为Map数据没有传递进来,无法继续写下去
    }
    public void qu(String id) {
        System.out.println("请输入取款金额:");
        int money = sc.nextInt();
        // 因为Map数据没有传递进来,无法继续写下去
    }
}



[ 本帖最后由 星辰浩月 于 2009-8-30 21:49 编辑 ]
搜索更多相关的解决方案: 取款机  ATM  

----------------解决方案--------------------------------------------------------
  相关解决方案