您好,登錄后才能下訂單哦!
這篇文章主要講解了“Java如何實現(xiàn)ATM銀行管理系統(tǒng)控制臺版本”,文中的講解內(nèi)容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Java如何實現(xiàn)ATM銀行管理系統(tǒng)控制臺版本”吧!
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 "醫(yī)??ㄌ枮椋?quot;+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管理系統(tǒng)======="); System.out.print("1.開戶\n2.登錄\n3.取款\n4.存款\n5.余額查詢\n6.修改密碼\n7.查看用戶信息\n8.退出登錄\n9.退出系統(tǒng)\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("歡迎下次登錄該系統(tǒng)!"); //退出系統(tǒng) 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.醫(yī)??╘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管理系統(tǒng)=======
1.開戶
2.登錄
3.取款
4.存款
5.余額查詢
6.修改密碼
7.查看用戶信息
8.退出登錄
9.退出系統(tǒng)
請選擇需要選擇的項目:1
=======================
1.普通銀行卡
2.信用卡
3.醫(yī)保卡
0.返回
請選擇開戶類型:1
請輸入姓名:admin
請輸入性別:男
請輸入年齡:22
請輸入身份證號:513922199555555555
請輸入銀行卡要設置的密碼:123456
請再次輸入密碼:123456
=======================
開戶成功!你的卡號為:1
=======ATM管理系統(tǒng)=======
1.開戶
2.登錄
3.取款
4.存款
5.余額查詢
6.修改密碼
7.查看用戶信息
8.退出登錄
9.退出系統(tǒng)
請選擇需要選擇的項目:
2
請輸入卡號:1
請輸入密碼:123456
=======================
admin,歡迎登錄!
=======ATM管理系統(tǒng)=======
1.開戶
2.登錄
3.取款
4.存款
5.余額查詢
6.修改密碼
7.查看用戶信息
8.退出登錄
9.退出系統(tǒng)
請選擇需要選擇的項目:
感謝各位的閱讀,以上就是“Java如何實現(xiàn)ATM銀行管理系統(tǒng)控制臺版本”的內(nèi)容了,經(jīng)過本文的學習后,相信大家對Java如何實現(xiàn)ATM銀行管理系統(tǒng)控制臺版本這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。