银行储蓄柜台综合业务平台
Customer
import java.io.Serializable; /** * @author Administrator *姓名:name 密码:mima 身份证号:id 电话号:num 钱数:money 卡号:mark 状态status */ public class Customer implements Serializable { private static final long serialVersionUID = 1L; private String name; private String mima; private String id; private String num; private int money = 0; private String mark; private int status; public int getStatus() { return status; } public void setStatus(int status) { this.status = status; } public String getName() { return name; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getNum() { return num; } public void setNum(String num) { this.num = num; } public void setName(String name) { this.name = name; } public int getMoney() { return money; } public void setMoney(int money) { this.money = money; } public String getMark() { return mark; } public void setMark(String mark) { this.mark = mark; } public String getMima() { return mima; } public void setMima(String mima) { this.mima = mima; } public Customer(String name, String mima, String id, String num, int money, String mark) { super(); this.name = name; this.mima = mima; this.id = id; this.num = num; this.money = money; this.mark = mark; } public Customer() { super(); // TODO Auto-generated constructor stub } public void tell() { System.out.println("***************************************"); System.out.println("姓名:" + this.name); System.out.println("身份证号:" + this.id); System.out.println("电话号:" + this.num); System.out.println("余额:" + this.money); System.out.println("*****************************************"); } }
Line
/** * @author Administrator *显示界面 */ public class Line { public void line() { System.out.println("*************银行储蓄柜台综合业务平台*************"); } public void line1() { System.out.println("\t\t\t1.开户\t\t\t"); } public void line2() { System.out.println("\t\t\t2.存款\t\t\t"); } public void line3() { System.out.println("\t\t\t3.取款\t\t\t"); } public void line4() { System.out.println("\t\t\t4.查询\t\t\t"); } public void line5() { System.out.println("\t\t\t5.转账\t\t\t"); } public void line6() { System.out.println("\t\t\t6.冻结\t\t\t"); } public void line7() { System.out.println("\t\t\t7.解冻\t\t\t"); } public void line8() { System.out.println("\t\t\t8.挂失\t\t\t"); } public void line9() { System.out.println("\t\t\t9.解除挂失\t\t\t"); } public void line10() { System.out.println("\t\t\t10.注销\t\t\t"); } public void line11() { System.out.println("\t\t\t11.用户修改密码\t\t\t"); } public void line12() { System.out.println("\t\t\t12.修改管理密码\t\t\t"); } public void line13() { System.out.println("\t\t\t13.退出\t\t\t"); } public void line14() { System.out .println("**************************************************"); } }
/** * @author Administrator *管理者类 *账号 usename *密码password */ public class User { private String usename; private String password; public String getUsename() { return usename; } public void setUsename(String usename) { this.usename = usename; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
Util
import java.io.Console; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.HashMap; import java.util.Properties; import java.util.Random; import java.util.Scanner; /** * @author Administrator * */ public class Util { public static String mark; public static String inputAccount() { Scanner input = new Scanner(System.in); System.out.print("请输入账号:"); return input.next(); } public static String inputAccount(String str) { Scanner input = new Scanner(System.in); System.out.print(str); return input.next(); } public static int inputAccount1(String str) { Scanner input = new Scanner(System.in); System.out.print(str); return input.nextInt(); } public static String inputPassword() { Console c = System.console(); return new String(c.readPassword("请输入密码:")); } public static String inputOldPassword() { Console c = System.console(); return new String(c.readPassword("请输入旧密码:")); } public static String inputNewPassword() { Console c = System.console(); return new String(c.readPassword("请输入新密码:")); } public static String inputTwoNewPassword() { Console c = System.console(); return new String(c.readPassword("请再次输入新密码:")); } public static int inputChoose() { Scanner input = new Scanner(System.in); System.out.print("请选择:"); return input.nextInt(); } /** * choose1()开户 * * @throws IOException */ public void choose1() throws IOException { // 显示头文件 创建对象 Line l = new Line(); l.line(); l.line1(); l.line14(); // 录入姓名 String name; while (true) { name = Util.inputAccount("请输入姓名:"); if (name.matches("^[\u4e00-\u9fa5]{1,6}$")) { break; } else { System.out.println("姓名必须为三至六个汉字"); } } // 录入身份证号 char a[]; String id; while (true) { id = Util.inputAccount("请输入18位身份证号:"); if (id.matches("^\\d{17}(\\d|x)$")) { break; } else { System.out.println("请输入正确的身份证号"); } } // 录入密码 String b; String mm; String mm1 = null; do { mm = Util.inputPassword(); b = mm.toString(); if (b.length() < 6) { System.out.println("密码长度必须大于6!!"); continue; } else { mm1 = Util.inputTwoNewPassword(); if (mm.equals(mm1)) { break; } else { System.out.println("两次密码输入不一致,请重新输入"); } } } while (!mm.equals(mm1)); String mima = mm; // 录入手机号 String num; while (true) { num = Util.inputAccount("请输入联系电话(手机号或固定电话):"); if (num.matches("^[1]{1}[3,5,8,7]{1}\\d{9}$")) { break; } else { System.out.println("请输入正确的手机号"); } } // 录入金额 int mon; do { mon = Util.inputAccount1("请输入您要存的金额:"); if (mon > 0) { break; } else { System.out.println("金额数必须大于0,请重新输入"); } } while (mon < 0); int money = mon; // 随机得到卡号 String mark = Util.String1(); Customer c = new Customer(name, mima, id, num, money, mark); Util.stay(); System.out.println("恭喜开户成功!您账号是" + c.getMark() + "密码是" + c.getMima() + "请牢记!!"); writeCustomer(c); boolean flog = false; while (!flog) { flog = Util.yorn(); } } /** * choose2() 存钱 */ public void choose2() { Line l = new Line(); l.line(); l.line2(); l.line14(); mark = Util.inputAccount("请输入您的卡号:"); if (Util.eadCustomer(mark)) { boolean flog = Util.Login(mark); boolean flog1 = Util.status(); if (flog1) { if (flog) { int money = Util.inputAccount1("请输入你要存的钱数:"); int money1 = Util.readCustomer(mark).getMoney(); Customer c = Util.readCustomer(mark); if (money > 0) { c.setMoney(money + money1); writeCustomer(c); System.out.println("存钱操作成功!"); Util.stay(); } else { System.out.println("存钱操作失败!存的钱数不能是负数!"); } } else { System.out.println("账号或密码输入错误!系统自动转到主界面"); } } } else { System.out.println("卡号不存在,系统退出"); } Util.stay(); } /** * choose3()取款 */ public void choose3() { Line l = new Line(); l.line(); l.line3(); l.line14(); mark = Util.inputAccount("请输入您的卡号:"); if (Util.eadCustomer(mark)) { boolean flog = Util.Login(mark); boolean flog1 = Util.status(); if (flog1) { if (flog) { Customer c = Util.readCustomer(mark); int money = Util.inputAccount1("请输入你要取的钱数:"); if (money > Util.readCustomer(mark).getMoney()) { System.out.println("取钱操作失败!余额不足!"); } else if (money < 0) { System.out.println("取钱操作失败!取的钱数不能为负!"); } else if (money > 0) { c.setMoney(Util.readCustomer(mark).getMoney() - money); writeCustomer(c); System.out.println("取钱操作成功!"); } } else { System.out.println("账号或密码输入错误!系统自动转到主界面"); } } } else { System.out.println("卡号不存在,系统退出"); } Util.stay(); } /** * choose4() 查询用户信息 * * @throws IOException * @throws ClassNotFoundException */ public void choose4() throws IOException, ClassNotFoundException { Line l = new Line(); l.line(); l.line4(); l.line14(); mark = Util.inputAccount("请输入您的卡号:"); if (Util.eadCustomer(mark)) { boolean flog = Util.Login(mark); boolean flog1 = Util.status(); if (flog1) { if (flog) { Util.stay(); Util.readCustomer(mark).tell(); boolean flog2 = false; while (!flog2) { flog2 = Util.yorn(); } } else { System.out.println("账号或密码输入错误!系统自动转到主界面"); } } } else { System.out.println("卡号不存在,系统退出"); } Util.stay(); } public void choose5() { Line l = new Line(); l.line(); l.line5(); l.line14(); mark = Util.inputAccount("请输入您的卡号:"); if (Util.eadCustomer(mark)) { boolean flog = Util.Login(mark); boolean flog1 = Util.status(); if (flog1) { if (flog) { String str = Util.inputAccount("请输入你要转账的卡号:"); String str1 = Util.inputAccount("请再输入你要转账的卡号:"); if (str.equals(str1)) { int money = Util.inputAccount1("请输入转账金额:"); if (money > Util.readCustomer(mark).getMoney()) { System.out.println("转账操作失败!余额不足!"); } else if (money < 0) { System.out.println("转账操作失败!转账的钱数不能为负!"); } else if (money > 0) { Customer c = Util.readCustomer(mark); c.setMoney(Util.readCustomer(mark).getMoney() - money); writeCustomer(c); Customer c1 = Util.readCustomer(str); c1.setMoney(Util.readCustomer(str).getMoney() + money); writeCustomer(c1); System.out.println("转账操作成功!"); } } else { System.out.println("账号或密码输入错误!系统自动转到主界面"); } } } } else { System.out.println("卡号不存在,系统退出"); } Util.stay(); } /** * choose6()冻结 */ public void choose6() { Line l = new Line(); l.line(); l.line6(); l.line14(); mark = Util.inputAccount("请输入您的卡号:"); if (Util.eadCustomer(mark)) { boolean flog = Util.Login(mark); boolean flog1 = Util.status(); if (flog1) { if (flog) { String str = Util.inputAccount("你要确认冻结吗?y/确定 n退出"); if (str.equalsIgnoreCase("y")) { Customer c = Util.readCustomer(mark); int i = 1; c.setStatus(i); writeCustomer(c); System.out.println("冻结操作成功"); } else { System.out.println("账号或密码输入错误!系统自动转到主界面"); } } } } else { System.out.println("卡号不存在,系统退出"); } Util.stay(); } /** * choose7()解冻 */ public void choose7() { Line l = new Line(); l.line(); l.line7(); l.line14(); mark = Util.inputAccount("请输入您的卡号:"); if (Util.eadCustomer(mark)) { boolean flog = Util.Login(mark); if (Util.readCustomer(mark).getStatus() == 1) { if (flog) { Customer c = Util.readCustomer(mark); int i = 0; c.setStatus(i); writeCustomer(c); System.out.println("解除冻结操作成功"); } else { System.out.println("账号或密码输入错误!系统自动转到主界面"); } } else { System.out.println("该用户未冻结"); } } else { System.out.println("卡号不存在,系统退出"); } Util.stay(); } /** * choose8()挂失 */ public void choose8() { Line l = new Line(); l.line(); l.line8(); l.line14(); mark = Util.inputAccount("请输入您的卡号:"); if (Util.eadCustomer(mark)) { boolean flog = Util.Login(mark); if (flog) { Customer c = Util.readCustomer(mark); int i = 2; c.setStatus(i); writeCustomer(c); } else { System.out.println("账号或密码输入错误!系统自动转到主界面"); } System.out.println("挂失操作成功"); } else { System.out.println("卡号不存在,系统退出"); } Util.stay(); } /** * choose9()解除挂失 */ public void choose9() { Line l = new Line(); l.line(); l.line9(); l.line14(); mark = Util.inputAccount("请输入您的卡号:"); if (Util.eadCustomer(mark)) { boolean flog = Util.Login(mark); if (Util.readCustomer(mark).getStatus() == 2) { if (flog) { Customer c = Util.readCustomer(mark); int i = 0; c.setStatus(i); writeCustomer(c); System.out.println("解除挂失操作成功"); } else { System.out.println("该用户未挂失"); } } else { System.out.println("账号或密码输入错误!系统自动转到主界面"); } } else { System.out.println("卡号不存在,系统退出"); } Util.stay(); } /** * choose10()注销 */ public void choose10() { Line l = new Line(); l.line(); l.line10(); l.line14(); mark = Util.inputAccount("请输入您的卡号:"); if (Util.eadCustomer(mark)) { boolean flog = Util.Login(mark); if (!(Util.readCustomer(mark).getStatus() == 1 || Util .readCustomer(mark).getStatus() == 2)) { if (flog) { String str = Util.inputAccount("你要确认注销吗?y/确定 n退出"); if (str.equalsIgnoreCase("y")) { Util.removeCustomer(mark); System.out.println("注销成功"); } } else { System.out.println("账号或密码输入错误!系统自动转到主界面"); } } else { System.out.println("该用户已挂失或冻结"); } } else { System.out.println("卡号不存在,系统退出"); } Util.stay(); } /** * choose()修改用户密码 */ public void choose11() { Line l = new Line(); l.line(); l.line11(); l.line14(); mark = Util.inputAccount("请输入您的卡号:"); if (Util.eadCustomer(mark)) { boolean flog = Util.Login(mark); boolean flog1 = Util.status(); if (flog1) { if (flog) { String str = Util.inputOldPassword(); if (Util.readCustomer(mark).getMima().equals(str)) { String str1 = Util.inputNewPassword(); String str2 = Util.inputTwoNewPassword(); if (str1.equals(str2)) { Customer c = Util.readCustomer(mark); c.setMima(str1); Util.writeCustomer(c); System.out.println("密码修改成功,请牢记新密码!!"); } else { System.out.println("两次密码输入不一致"); } } else { System.out.println("旧密码输入错误"); } } else { System.out.println("您输入的账号或密码不正确"); } } else { System.out.println("该用户已挂失或冻结"); } } else { System.out.println("卡号不存在,系统退出"); } Util.stay(); } /** * choose12()修改管理密码 */ public void choose12() { Line l = new Line(); l.line(); l.line12(); l.line14(); Properties p = new Properties(); try { p.load(new FileInputStream("e:/db/a.properties")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String str = md("MD5", Util.inputOldPassword()); if (p.getProperty("password").equals(str)) { String str1 = Util.inputNewPassword(); String str2 = Util.inputTwoNewPassword(); if (str1.equals(str2)) { p.setProperty("password", md("MD5", str2)); try { p.store(new FileOutputStream("e:/db/a.properties"), null); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("密码修改成功!"); } else { System.out.println("两次输入的旧密码不一样!"); } } else { System.out.println("旧密码错误!"); } Util.stay(); } /** * writeCustomer(Customer cus) 将对象写入HashMap 列表中并通过write()方法将对象写入文件中 * * @param account */ public static void writeCustomer(Customer cus) { HashMap<String, Customer> m = new HashMap<String, Customer>(); try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream( "e:db/db.dat")); m = (HashMap<String, Customer>) ois.readObject(); m.put(cus.getMark(), cus); write(m); ois.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } Util.stay(); } /** * 注销用户 * * @param mark */ public static void removeCustomer(String mark) { HashMap<String, Customer> m = new HashMap<String, Customer>(); try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream( "e:db/db.dat")); m = (HashMap<String, Customer>) ois.readObject(); m.remove(mark); write(m); ois.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } Util.stay(); } /** * * @param ha * write(HashMap<String,Customer> ha) 传来HashMap对象列表 将对象写入文件中 */ public static void write(HashMap<String, Customer> ha) { ; try { ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream("e:/db/db.dat")); oos.writeObject(ha); oos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * @param id * @return ReadCustomer(String id) 方法 通过HashMap 关键字 读取对象 并且返回对象 */ public static Customer readCustomer(String mark) { HashMap<String, Customer> hm = new HashMap<String, Customer>(); Customer c = new Customer(); try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream( "e:/db/db.dat")); hm = (HashMap<String, Customer>) ois.readObject(); c = hm.get(mark); ois.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return c; } public static boolean eadCustomer(String mark) { boolean flog = false; HashMap<String, Customer> hm = new HashMap<String, Customer>(); Customer c = new Customer(); try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream( "e:/db/db.dat")); hm = (HashMap<String, Customer>) ois.readObject(); if (hm.containsKey(mark)) { flog = true; } // Set<String> set = hm.keySet(); // for (String str : set) { // if (str.equals(mark)) { // flog = true; // break; // } else { // flog = false; // } // } ois.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return flog; } /** * String()生成随机卡号 * * @return */ public static String String1() { String str = "0123456789"; StringBuilder s = new StringBuilder(); int len = 5; for (int i = 0; i <= len; i++) { Random r = new Random(); int p = r.nextInt(str.length()); s.append(str.charAt(p)); } return s.toString(); } /** * md(String md, String pass)密码加密 * * @param md * @param pass * @return */ public static String md(String md, String pass) { MessageDigest m; String passok = ""; try { m = MessageDigest.getInstance(md); m.update(pass.getBytes()); for (byte b : m.digest()) { passok += String.format("%x", b); } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return passok; } /** * stay()等待2秒 */ public static void stay() { try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } } /** * 验证用户登录账号密码 * * @return */ public static boolean Login(String mark) { String str1 = Util.inputPassword(); if (Util.readCustomer(mark).getMima().equals(str1)) { return true; } else { System.out.println("账号或密码错误!"); return false; } } /** * 判断用户状态 * * @return */ public static boolean status() { if (Util.readCustomer(mark).getStatus() == 0) { return true; } else if (Util.readCustomer(mark).getStatus() == 1) { System.out.println("该账号已被冻结"); return false; } else if (Util.readCustomer(mark).getStatus() == 2) { System.out.println("该账号已被挂失"); return false; } else { return false; } } /** * 判断返回主界面 * * @return */ public static boolean yorn() { String str = Util.inputAccount("按y键返回主界面..."); if (str.equals("y")) { return true; } else { return false; } } }