===============欢迎=============
1:查询账户
2:存款
3:取款
4:转账
5:修改密码
6:退出
7:注销账号
package com.sxt; public class Accpunt { //传入卡号,用户名,密码,余额,限取额度 private String idName; private String userName; private String password; private double money; private double quotaMoney; //创建无参构造 public Accpunt() { } //传入有参构造 public Accpunt(String idName, String userName, String password, double quotaMoney) { this.idName = idName; this.userName = userName; this.password = password; this.quotaMoney = quotaMoney; } //传入getset方法 public double getQuotaMoney() { return quotaMoney; } public void setQuotaMoney(double quotaMoney) { this.quotaMoney = quotaMoney; } public double getMoney() { return money; } public void setMoney(double money) { this.money = money; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getIdName() { return idName; } public void setIdName(String idName) { this.idName = idName; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } }
public class ATMSystem { private static Object Accpunt; public static void main(String[] args) { //创建数组存储账户 ArrayList accounts = new ArrayList<>(); //调用showMain showMain(accounts); } //创建展示窗口类 public static void showMain(ArrayList accpunts) { System.out.println("==========欢迎使用=========="); Scanner sc=new Scanner(System.in); while (true) { System.out.println("请选择 *** 作 1:登录 2:开户"); int commond=sc.nextInt(); switch (commond) { case 1: //登录 login(accpunts,sc); break; case 2: //开户 register(accpunts,sc); break; default: System.out.println("输入错误,请重新输入:"); } } } private static void showUserCommand(Scanner sc,Accpunt acc,ArrayList accpunts) { System.out.println("===============欢迎============="); while (true) { 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("7:注销账号"); int commmand=sc.nextInt(); switch (commmand) { case 1: //查询账户 showAccount(acc); break; case 2: //存款" dispoteMoney(acc,sc); break; case 3: //取款 drawMoney(acc,sc); break; case 4: //转账 transferMoney(acc,sc,accpunts); break; case 5: //修改密码 updatePassword(acc,sc); return; case 6: //退出 System.out.println("欢迎下次使用!"); return; case 7: //注销账号 accpunts.remove(acc); System.out.println("销户成功"); return; default: System.out.println("你的输入有误,请重新输入!"); } } } private static void updatePassword(com.sxt.Accpunt acc, Scanner sc) { System.out.println("=======修改密码========"); while (true) { System.out.println("请你输入旧密码:"); String okPassword=sc.next(); if (acc.getPassword().equals(okPassword)) { System.out.println("请你输入新密码"); String newPassword=sc.next(); if (newPassword.equals(okPassword)) { System.out.println("和旧密码一样,请你重新输入"); }else { System.out.println("请你确定新密码"); String newOkPassword=sc.next(); if (newOkPassword.equals(newPassword)) { acc.setPassword(newPassword); return; }else { System.out.println("两次密码不一致"); } } }else { System.out.println("密码不对,请你重新输入"); } } } private static void transferMoney(com.sxt.Accpunt acc, Scanner sc, ArrayListaccpunts) { if (accpunts.size()<2) { System.out.println("当前系统账户小于2个"); return; } if (acc.getMoney()==0) { System.out.println("你的余额为0,请先冲值"); return; } while (true) { System.out.println("请你输入对方卡号:"); String careId =sc.next(); Accpunt account = getAccountByCardId(careId, accpunts); if (account != null) { if (account.getIdName().equals(acc.getIdName())) { System.out.println("请不要向自己充值"); } else { String name = "*" + account.getUserName().substring(1); System.out.println("你要向" + name + "转账,请你确定姓氏:"); String preName = sc.next(); if (account.getUserName().startsWith(preName)) { while (true) { System.out.println("请你输入转帐金额:"); Double money = sc.nextDouble(); if (money > acc.getMoney()) { System.out.println("余额不足"); } else { acc.setMoney(acc.getMoney() - money); account.setMoney(account.getMoney() + money); showAccount(acc); return; } } } else { System.out.println("姓输入不对"); } } } else { System.out.println("卡号不存在,请你重新输入"); } } } private static void drawMoney(com.sxt.Accpunt acc, Scanner sc) { System.out.println("=========取款 *** 作========="); if (acc.getMoney()>=100) { while (true) { System.out.println("请你输入当初取款额度:"); Double money=sc.nextDouble(); if (money>acc.getQuotaMoney()) { System.out.println("取款 *** 过额度,你的取款额度为"+acc.getQuotaMoney()+"请你重新输入"); } else { if (acc.getMoney() 欢迎分享,转载请注明来源:内存溢出
评论列表(0条)