一.业务分析

通过使用Java面向对象的基础知识,开发一个ATM系统,实现存款,取款,转账,修改密码,注销账户等功能。

二.开发准备

首先,创建一个用户类,为建立用户对象做准备,用户类主要包括用户卡号(系统随机生成),用户名,账户密码,余额,取现额度。并搭建构造器,以及get,set。

public class user {private String cardId ;     //卡号private String username;    //用户名private String password;    //密码private double money;       //余额private double qumoney;     //取现额度public user(String cardId, String username, String password,  double qumoney) {this.cardId = cardId;this.username = username;this.password = password;this.qumoney = qumoney;}public user() {}public String getCardId() {return cardId;}public void setCardId(String cardId) {this.cardId = cardId;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public double getMoney() {return money;}public void setMoney(double money) {this.money = money;}public double getQumoney() {return qumoney;}public void setQumoney(double qumoney) {this.qumoney = qumoney;}
}

三.创建测试类,写入main方法

public class ATMSystem {public static void main(String[] args) {ArrayList<user> users = new ArrayList<>();Main(users);}

四.将主界面设置成Main方法,设计主界面,包括登录账户,注册账户,并且设置登录方法,注册方法,再调用。

public static void Main(ArrayList<user> users) {System.out.println("==========欢迎进入xx银行ATM系统==========");while (true) {System.out.println("请选择操作:");System.out.println("1.登录账户");System.out.println("2.注册账户");Scanner sc = new Scanner(System.in);int command = sc.nextInt();switch (command) {case 1:                 //登录denglu(users, sc);break;case 2:                 //注册zhuce(users, sc);break;default:System.out.println("功能不存在!");}}}

运行结果:

五.将注册账户写成方法

public static void zhuce(ArrayList<user> users, Scanner sc) {System.out.println("==========注册账户==========");String password = "";String password2 = "";System.out.println("请输入您的账号名称:");sc = new Scanner(System.in);String name = sc.next();while (true) {System.out.println("请输入您的账号密码:");password = sc.next();System.out.println("请您再次输入密码:");password2 = sc.next();if (password2.equals(password)) {break;} else {System.out.println("两次密码输入不一致!,请重新输入");}}//生成卡号System.out.println("请输入账号当次限额");double qumoney = sc.nextDouble();String cardId = kahao(users);user u1 = new user(cardId, name, password, qumoney);users.add(u1);System.out.println("恭喜开户成功!,您的卡号是" + u1.getCardId() + ",请您保管");}

其中,涉及到生成卡号,以及查询系统生成的卡号是否相同,需要再写两个方法:

//生成卡号public static String kahao(ArrayList<user> users) {while (true) {Random rs = new Random();String cardId = "";for (int i = 0; i < 8; i++) {cardId += rs.nextInt(10);}user a = getcardId(cardId, users);if (a == null) {//无重复return cardId;}}}
//查询卡号public static user getcardId(String kahao, ArrayList<user> users) {for (int i = 0; i < users.size(); i++) {user a = users.get(i);if (a.getCardId().equals(kahao)) {return a;}}return null;}

六.将登录账户写成方法,并设计主界面

public static void denglu(ArrayList<user> users, Scanner sc) {System.out.println("==========登录账户==========");if (users.size() == 0) {System.out.println("系统中无账户!请先注册");return;}while (true) {System.out.println("请输入您的卡号:");String cardId = sc.next();String password = "";user acc = getcardId(cardId, users);if (acc != null) {while (true) {System.out.println("请输入您的密码:");password = sc.next();//判断密码是否正确if (acc.getPassword().equals(password)) {System.out.println("登录成功!,欢迎卡号" + acc.getCardId() + "的贵宾" + acc.getUsername() + "进入系统");//展示系统登录后的操作界面jiemian(sc, acc, users);return;} else {System.out.println("密码错误!请重新输入");}}} else {System.out.println("不存在该卡号!");}}}

六.1编写 展示主界面方法

public static void jiemian(Scanner sc, user acc, ArrayList<user> users) {while (true) {System.out.println("==========欢迎进入xx银行用户操作界面===========");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("7.注销当前账户");sc = new Scanner(System.in);int commend = sc.nextInt();switch (commend) {case 1:atm1(acc);break;case 2:atm2(acc, sc);break;case 3:atm3(acc, sc);break;case 4:atm4(users, acc, sc);break;case 5:atm5(acc, sc);return;case 6:System.out.println("欢迎下次来到ATM系统");return;case 7:System.out.println("是否确认注销账户?按1确认,按2取消注销");int tf = sc.nextInt();if (tf == 1) {users.remove(acc);System.out.println("注销成功!");return;} else {System.out.println("取消注销");break;}default:System.out.println("不存在该功能!");}}}

七.接下来,依次编写各个功能的方法

//查询功能private static void atm1(user acc) {System.out.println("========当前账户详情=========");System.out.println("卡号:" + acc.getCardId());System.out.println("姓名:" + acc.getUsername());System.out.println("余额:" + acc.getMoney());System.out.println("当次取款限额:" + acc.getQumoney());}//存款功能private static void atm2(user acc, Scanner sc) {System.out.println("=========存款操作=========");System.out.println("请您输入存款金额:");double money = sc.nextDouble();acc.setMoney(acc.getMoney() + money);System.out.println("存款成功!");atm1(acc);}//取款private static void atm3(user acc, Scanner sc) {System.out.println("=========取款操作=========");if (acc.getMoney() < 100) {System.out.println("您的账户余额不足100元!无法取款");return;} else {while (true) {System.out.println("请您输入取款金额:");double money = sc.nextDouble();if (money > acc.getMoney()) {System.out.println("账户余额不足!");System.out.println("继续取款按1,退出取款按2");int commend = sc.nextInt();switch (commend) {case 1:break;case 2:return;}} else if (money > acc.getQumoney()) {System.out.println("超过了当次取款限额!,每次最多可以取" + acc.getQumoney() + "元");} else {System.out.println("取款成功!");acc.setMoney(acc.getMoney() - money);atm1(acc);return;}}}}//转账private static void atm4(ArrayList<user> users, user acc, Scanner sc) {System.out.println("=========转账操作=========");//判断系统中是否有两个以上账户if (users.size() < 2) {System.out.println("系统中无其他账户,不可以转账!");return;} else {if (acc.getMoney() == 0) {System.out.println("您的账户余额为0,无法转账");return;} else {while (true) {System.out.println("请输入对方的卡号:");String dui = sc.next();user c = getcardId(dui, users);if (c != null) {//判断账户对象是否为自己if (c.getCardId().equals(acc.getCardId())) {System.out.println("不能给自己转账!");} else {//确认对方姓氏String name = "*" + c.getUsername().substring(1);System.out.println("请您确认[" + name + "]的姓氏");String xingshi = sc.next();if (c.getUsername().startsWith(xingshi)) {System.out.println("输入正确!");while (true) {System.out.println("请您输入转账金额:");double money = sc.nextDouble();if (money > acc.getMoney()) {System.out.println("余额不足!");System.out.println("继续转账按1,退出转账按2");int commend = sc.nextInt();switch (commend) {case 1:break;case 2:return;}} else {acc.setMoney(acc.getMoney() - money);c.setMoney(c.getMoney() + money);System.out.println("为" + c.getUsername() + "用户" + "转账成功");atm1(acc);return;}}} else {System.out.println("对不起,您输入的信息有误!");}}} else {System.out.println("对不起,您输入卡号有误!");}}}}}//修改密码操作private static void atm5(user acc, Scanner sc) {System.out.println("=========修改密码操作=========");while (true) {System.out.println("请输入您的旧密码:");String oldpassword = sc.next();String newpassword = "";if (oldpassword.equals(acc.getPassword())) {while (true) {System.out.println("请输入新密码:");newpassword = sc.next();if (newpassword.equals(oldpassword)) {System.out.println("新密码不能与旧密码重复!");} else {System.out.println("请再次输入密码:");String okpassword = sc.next();if (newpassword.equals(okpassword)) {System.out.println("修改密码成功!");acc.setPassword(newpassword);return;} else {System.out.println("两次密码输入不一致!");}}}}else{System.out.println("旧密码输入错误!");}}}

至此,所有功能完成。

感谢观看!

基于Java的ATM系统相关推荐

  1. 抽奖功能java开发_基于Java实现抽奖系统

    摘要:这篇Java开发技术栏目下的"基于Java实现抽奖系统",介绍的技术点是"抽奖系统.Java.抽奖.基于.系统.实现",希望对大家开发技术学习和问题解决有 ...

  2. 基于JAVA宠物托管系统计算机毕业设计源码+系统+lw文档+部署

    基于JAVA宠物托管系统计算机毕业设计源码+系统+lw文档+部署 基于JAVA宠物托管系统计算机毕业设计源码+系统+lw文档+部署 本源码技术栈: 项目架构:B/S架构 开发语言:Java语言 开发软 ...

  3. 基于Java毕业设计房屋租赁系统源码+系统+mysql+lw文档+部署软件

    基于Java毕业设计房屋租赁系统源码+系统+mysql+lw文档+部署软件 基于Java毕业设计房屋租赁系统源码+系统+mysql+lw文档+部署软件 本源码技术栈: 项目架构:B/S架构 开发语言: ...

  4. 基于JAVA汽车租赁系统计算机毕业设计源码+系统+lw文档+部署

    基于JAVA汽车租赁系统计算机毕业设计源码+系统+lw文档+部署 基于JAVA汽车租赁系统计算机毕业设计源码+系统+lw文档+部署 本源码技术栈: 项目架构:B/S架构 开发语言:Java语言 开发软 ...

  5. 基于JAVA图书借阅系统的设计与实现计算机毕业设计源码+系统+lw文档+部署

    基于JAVA图书借阅系统的设计与实现计算机毕业设计源码+系统+lw文档+部署 基于JAVA图书借阅系统的设计与实现计算机毕业设计源码+系统+lw文档+部署 本源码技术栈: 项目架构:B/S架构 开发语 ...

  6. 基于JAVA汽车租赁系统计算机毕业设计源码+数据库+lw文档+系统+部署

    基于JAVA汽车租赁系统计算机毕业设计源码+数据库+lw文档+系统+部署 基于JAVA汽车租赁系统计算机毕业设计源码+数据库+lw文档+系统+部署 本源码技术栈: 项目架构:B/S架构 开发语言:Ja ...

  7. 基于Java毕业设计在线答题系统源码+系统+mysql+lw文档+部署软件

    基于Java毕业设计在线答题系统源码+系统+mysql+lw文档+部署软件 基于Java毕业设计在线答题系统源码+系统+mysql+lw文档+部署软件 本源码技术栈: 项目架构:B/S架构 开发语言: ...

  8. 基于JAVA汽车租赁系统 (Springboot框架) 开题报告

      本科生毕业论文 基于Java(springboot框架)汽车租赁系统 开题报告 学    院: 专    业: 计算机科学与技术 年    级: 学生姓名: 指导教师:   XXXX大学本科生毕业 ...

  9. 基于java的oa协同办公系统_基于JAVA的OA系统的制作毕业设计论文

    <基于JAVA的OA系统的制作毕业设计论文.doc>由会员分享,可免费在线阅读全文,更多与<基于JAVA的OA系统的制作毕业设计论文>相关文档资源请在帮帮文库(www.woc8 ...

最新文章

  1. Android应用屏幕适应问题的解决
  2. opengl 深度详解_OpenGL中的深度测试
  3. python快速入门神器 知乎_python数据分析之数据处理终极神器
  4. 【论文笔记】One Millisecond Face Alignment with an Ensemble of Regression Trees
  5. Windows系统下搭建Git本地代码库
  6. java备份mysql数据库备份_Java实现MySQL数据库备份
  7. Python查找任意字符串中只出现一次的字符(2016奇虎笔试题)
  8. 「2012-12-29」3x3手机锁屏矩阵图像的组合数量
  9. 云计算与 Cloud Native | 数人云CEO王璞@KVM分享实录
  10. 什么是计算机病毒?是怎么产生的?
  11. 设计模式:简单工厂模式(C++实现)
  12. 视频教程-第03章-二进制、八进制、十进制、十六进制之间的转换-网络技术
  13. 乱谈那些个著名的科技互联网公司和产品名字
  14. Windows驱动一些概念WDK WDF WDM WDI
  15. 层叠上下文(stacking context)
  16. 【fpdlink】FPDlink接口---TI954解串器功能分析
  17. Imagewarping变形算法研究---MLSR(Nonrigid image deformation using moving regularized least quares)
  18. 高德h5定位误差_#高德地图api移动端定位失败解决方案 #H5 原生Geollocation接口Chomre浏览器的坑...
  19. 菜鸟成长手册:路由器技术深入剖解
  20. 2. 认识O(logN)的排序

热门文章

  1. 1、Canopen 轻松入门
  2. 收藏 |2019互联网安全与DDoS态势研究报告解读Pro版
  3. android----Android语音播报的两种简单实现
  4. linux基础——echo
  5. 2020年高教社杯全国大学生数学建模竞赛 C题思路
  6. 餐厅菜单html代码,html5css3 3D餐厅菜单概念_订餐菜单选择工具
  7. could not create folder “sftp://xxx.xxx.xxx.xxx/.../venv“. (Permission denied)
  8. 用js将简体转换为繁体
  9. sphinx 配置文件全解析
  10. 【bzoj4372】 烁烁的游戏【动态树分治】