这篇文章主要讲解了“Java如何实现ATM银行管理系统控制台版本”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Java如何实现ATM银行管理系统控制台版本”吧!
abstract class Card { int cardId; public Card() { super(); } public Card(int cardId) { super(); this.cardId = cardId; } public abstract String getCardId(); public abstract void setCardId(int cardId); }
public class CommonCard extends Card{ public CommonCard() { super(); } public CommonCard(int cardId) { super(); this.cardId = cardId; } @Override public String getCardId() { return "普通银行卡卡号为:"+cardId; } @Override public void setCardId(int cardId) { this.cardId = cardId; } }
package com.railway.modules.base.test; public class CreditCard extends Card{ public CreditCard() { super(); } public CreditCard(int cardId) { super(cardId); } @Override public String getCardId() { return "信用卡卡号为:"+cardId; } @Override public void setCardId(int cardId) { this.cardId = cardId; } }
package com.railway.modules.base.test; public class MedicalInsuranceCard extends Card{ public MedicalInsuranceCard() { super(); } public MedicalInsuranceCard(int cardId) { super(cardId); } @Override public String getCardId() { return "医保卡卡号为:"+cardId; } @Override public void setCardId(int cardId) { this.cardId = cardId; } }
package com.railway.modules.base.test; import java.util.Scanner; public class ATM { Scanner input = new Scanner(System.in); private User[] user=new User[100]; User atm = new User(); private User usr; private int accountId = 1; private Card card; public void Select() { while(true) { System.out.println("=======ATM管理系统======="); System.out.print("1.开户\n2.登录\n3.取款\n4.存款\n5.余额查询\n6.修改密码\n7.查看用户信息\n8.退出登录\n9.退出系统\n请选择需要选择的项目:"); switch(input.nextInt()) { case 1: setAccount(); //开户 break; case 2: usr=userLogin(); //登录 break; case 3: drawMoney(); //取款 break; case 4: depositMoney(); //存款 break; case 5: showBalance(); //余额查询 break; case 6: revisePassword(); //修改密码 break; case 7: lookAccount(); //查看用户信息 break; case 8: cancel();//退出登录 break; case 9: System.out.println("======================="); System.out.println("欢迎下次登录该系统!"); //退出系统 System.exit(0); break; default: System.out.println("======================="); System.out.println("输入错误!请重新输入!"); break; } } } public void setAccount(){ //开户 if (usr!=null) { System.out.println("======================="); System.out.println("请先退出上一个账户!"); } else{ boolean x = true; while(x) { System.out.println("======================="); System.out.print("1.普通银行卡\n2.信用卡\n3.医保卡\n0.返回\n请选择开户类型:"); switch(input.nextInt()) { case 1: card = new CommonCard(); card.setCardId(accountId); x=false; break; case 2: card = new CreditCard(); card.setCardId(accountId); x=false; break; case 3: card = new MedicalInsuranceCard(); card.setCardId(accountId); x=false; break; case 0: Select(); default: System.out.println("======================="); System.out.println("输入错误!请重新输入!"); break; } } System.out.print("请输入姓名:"); String name=input.next(); System.out.print("请输入性别:"); String sex=input.next(); System.out.print("请输入年龄:"); String age=input.next(); System.out.print("请输入身份证号:"); String ID=input.next(); System.out.print("请输入银行卡要设置的密码:"); String password1=input.next(); System.out.print("请再次输入密码:"); String password2=input.next(); if(password1.equals(password2)){ user[accountId]=new User(name,sex,age,password1,ID,0,card); System.out.println("======================="); System.out.println("开户成功!你的卡号为:"+accountId); accountId++; } else { System.out.println("======================="); System.out.println("两次密码不同!请重新开始!"); } } } public User userLogin(){ //登录 if (usr!=null) { System.out.println("======================="); System.out.println("请先退出上一个账户!"); return usr; } else{ System.out.print("请输入卡号:"); int aId=input.nextInt(); System.out.print("请输入密码:"); String password=input.next(); for(int i=0;i<user.length;i++){ if (user[i]!=null) { if (aId==user[i].getCard()&&password.equals(user[i].getPassword())) { System.out.println("======================="); System.out.println(user[i].getName()+",欢迎登录!"); return user[i]; } } } System.out.println("======================="); System.out.println("卡号或密码有误"); return null; } } public void drawMoney(){ //取款 if(usr==null){ System.out.println("======================="); System.out.println("请先登录账户!"); } else{ System.out.print("请输入取款金额:"); double blc=input.nextDouble(); while(blc>usr.getBalance()) { System.out.println("======================="); System.out.print("取款金额大于余额,请重新输入取款金额:"); blc=input.nextDouble(); } while(blc<=0){ System.out.println("======================="); System.out.print("取款金额错误,请重新输入取款金额:"); blc=input.nextDouble(); } usr.setBalance(usr.getBalance()-blc); System.out.println("======================="); System.out.println("取款成功!"); System.out.println("账户余额:"+usr.getBalance()); } } public void depositMoney(){ //存款 if(usr==null){ System.out.println("======================="); System.out.println("请先登录账户!"); } else{ System.out.print("请输入存款金额:"); double dsm=input.nextDouble(); while(dsm<=0){ System.out.println("======================="); System.out.print("输入金额错误,请重新输入:"); dsm=input.nextDouble(); } usr.setBalance(usr.getBalance()+dsm); System.out.println("======================="); System.out.println("存款成功!"); System.out.println("账户余额:"+usr.getBalance()); } } public void showBalance(){ //余额查询 if(usr==null){ System.out.println("======================="); System.out.println("请先登录账户!"); } else{ System.out.println("======================="); System.out.println("账户余额:"+usr.getBalance()); } } public void revisePassword(){ //修改密码 if(usr==null){ System.out.println("======================="); System.out.println("请先登录账户!"); } else{ System.out.print("请输入原密码:"); String password=input.next(); for(int i=2;i>=0;i--) { if(password.equals(usr.getPassword())) break; if(i==0) { System.out.println("三次密码输入错误!即将退出账户!"); cancel(); Select(); } System.out.println("密码错误!你还有"+i+"次机会!"); System.out.print("请输入原密码:"); password=input.next(); } System.out.print("验证成功,请输入新密码:"); String password1=input.next(); System.out.print("请再次输入密码:"); String password2=input.next(); while(!password1.equals(password2)) { System.out.println("======================="); System.out.print("两次密码不同,请重新输入新密码:"); password1=input.next(); System.out.print("请再次输入密码:"); password2=input.next(); } usr.setPassword(password1); System.out.println("======================="); System.out.println("修改成功!"); } } public void lookAccount() { //查看用户信息 if(usr==null){ System.out.println("======================="); System.out.println("请先登录账户!"); } else{ System.out.println("======================="); System.out.println("姓名:"+usr.getName()); System.out.println("性别:"+usr.getSex()); System.out.println(usr.getCardId()); System.out.println("身份证号:"+usr.getID()); System.out.println("余额:"+usr.getBalance()); } } public void cancel() { if(usr==null){ System.out.println("======================="); System.out.println("请先登录账户!"); } else{ usr=null; System.out.println("======================="); System.out.println("账户退出成功!"); } } }
public class TestATM { public static void main(String[] args) { ATM atm = new ATM(); atm.Select(); } }
=======ATM管理系统=======
1.开户
2.登录
3.取款
4.存款
5.余额查询
6.修改密码
7.查看用户信息
8.退出登录
9.退出系统
请选择需要选择的项目:1
=======================
1.普通银行卡
2.信用卡
3.医保卡
0.返回
请选择开户类型:1
请输入姓名:admin
请输入性别:男
请输入年龄:22
请输入身份证号:513922199555555555
请输入银行卡要设置的密码:123456
请再次输入密码:123456
=======================
开户成功!你的卡号为:1
=======ATM管理系统=======
1.开户
2.登录
3.取款
4.存款
5.余额查询
6.修改密码
7.查看用户信息
8.退出登录
9.退出系统
请选择需要选择的项目:
2
请输入卡号:1
请输入密码:123456
=======================
admin,欢迎登录!
=======ATM管理系统=======
1.开户
2.登录
3.取款
4.存款
5.余额查询
6.修改密码
7.查看用户信息
8.退出登录
9.退出系统
请选择需要选择的项目:
感谢各位的阅读,以上就是“Java如何实现ATM银行管理系统控制台版本”的内容了,经过本文的学习后,相信大家对Java如何实现ATM银行管理系统控制台版本这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。