java實(shí)現(xiàn)銀行ATM管理系統(tǒng)
本文實(shí)例為大家分享了java實(shí)現(xiàn)銀行ATM管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
功能
賬戶類、首頁(yè)設(shè)計(jì)
分析
① 每個(gè)用戶一個(gè)賬戶對(duì)象,需要設(shè)計(jì)賬戶類,賬戶類至少包含(卡號(hào)、用戶名、余額、取現(xiàn)額度、密碼)
② 需要定義一個(gè)ArrayList的集合用于存儲(chǔ)賬戶對(duì)象。
③ 需要展示歡迎頁(yè)包含2個(gè)功能:注冊(cè)開(kāi)戶、登錄賬戶。
用戶開(kāi)戶功能實(shí)現(xiàn)
① 開(kāi)戶功能應(yīng)該獨(dú)立定義成方法,并傳入當(dāng)前集合對(duì)象給該方法。
public static void register(ArrayList<Account> accounts) {…}
② 需要提示用戶輸入個(gè)人信息,開(kāi)戶的卡號(hào)是系統(tǒng)自動(dòng)生成的8位數(shù)。
public static String createCardId(){…}
③ 注意:自動(dòng)生成的卡號(hào)不能與其他用戶的卡號(hào)重復(fù)。
④ 最終把用戶開(kāi)戶的信息封裝成Account對(duì)象,存入到集合中。
用戶登錄功能實(shí)現(xiàn)
分析
① 需要根據(jù)卡號(hào)去集合中查詢對(duì)應(yīng)的賬戶對(duì)象。
② 如果找到了賬戶對(duì)象,說(shuō)明卡號(hào)存在,繼續(xù)輸入密碼。
③ 如果密碼也正確,則登錄成功。
用戶操作頁(yè)設(shè)計(jì)、查詢賬戶、退出賬戶功能
分析
① 用戶登錄成功后,需要進(jìn)入用戶操作頁(yè)。
② 查詢就是直接展示當(dāng)前登錄成功的賬戶對(duì)象的信息。
③ 退出賬戶是需要回到首頁(yè)的
用戶存款、取款功能設(shè)計(jì)
分析
① 存款和取款都是拿到當(dāng)前用戶的賬戶對(duì)象。
② 通過(guò)調(diào)用賬戶對(duì)象的set方法修改其余額。
用戶轉(zhuǎn)賬功能設(shè)計(jì)
分析
① 轉(zhuǎn)賬功能要分析對(duì)方賬戶是否存在的問(wèn)題。
② 還要分析自己的余額是否足夠的問(wèn)題。
用戶密碼修改功能、銷(xiāo)戶功能
分析
① 修改密碼就是把當(dāng)前對(duì)象的密碼屬性使用set方法進(jìn)行更新。
② 銷(xiāo)戶是從集合對(duì)象中刪除當(dāng)前對(duì)象,并回到首頁(yè)。
輸出流
import java.util.ArrayList; import java.util.Random; import java.util.Scanner;
首頁(yè)設(shè)計(jì)
public class Bank { ? ? public static void main(String[] args) { ? ? ? ? Scanner sc = new Scanner(System.in); ? ? ? ? ArrayList<Account> list = new ArrayList<>(); ? ? ? ? ? //首頁(yè)設(shè)計(jì) ? ? ? ? while(true){//while死循環(huán) ? ? ? ? ? System.out.println("========歡迎您進(jìn)入萬(wàn)和銀行ATM系統(tǒng)========"); ? ? ? ? System.out.println("1.登錄賬戶"); ? ? ? ? System.out.println("2.注冊(cè)開(kāi)戶"); ? ? ? ? System.out.println("請(qǐng)輸入命令1、2選擇對(duì)應(yīng)的操作");
首頁(yè)界面選擇
//首頁(yè)界面選擇 String choice =sc.next(); ? ?switch (choice){//switch語(yǔ)句使輸入的指令進(jìn)入不同的功能 ? ? ? ? ? ? ? ? case "1": ? ? ? ? ? ? ? ? ? ? System.out.println("========歡迎您進(jìn)入萬(wàn)和銀行用戶登錄界面========"); ? ? ? ? ? ? ? ? ? ? login(list); ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? case "2": ? ? ? ? ? ? ? ? ? ? System.out.println("========歡迎您進(jìn)入萬(wàn)和銀行用戶辦卡界面========"); ? ? ? ? ? ? ? ? ? ? register(list); ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? case "后臺(tái)統(tǒng)計(jì)"://為后臺(tái)統(tǒng)計(jì)數(shù)據(jù)使用,主界面直接輸入“后臺(tái)統(tǒng)計(jì)”可以顯示系統(tǒng)所有成員信息 ? ? ? ? ? ? ? ? ? ? System.out.println("========后臺(tái)統(tǒng)計(jì)========"); ? ? ? ? ? ? ? ? ? ? htlook(list); ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? default: ? ? ? ? ? ? ? ? ? ? System.out.println("您輸入的數(shù)字有誤,請(qǐng)重新輸入"); ? ? ? ? ?} ? ? } }
1、用戶登錄功能
// ?1、用戶登錄功能 public static void login(ArrayList<Account> list) { ? ? ? ? ? ? Scanner sc = new Scanner(System.in);//創(chuàng)建鍵盤(pán)錄入對(duì)象 ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入您的卡號(hào)"); ? ? ? ? ? ? String idcard = sc.next(); ? ? ? ? ? ? ? int index = getIndex(list, idcard);//調(diào)用方法判斷后臺(tái)是否有該卡號(hào) ? ? ? ? ? ? if (index == -1) { ? ? ? ? ? ? ? ? System.out.println("不存在該卡號(hào),請(qǐng)重新輸入"); ? ? ? ? ? ? } else { ? ? ? ? ? ? ? ? for (int i = 0; i < list.size(); i++) { ? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)您輸入您的密碼"); ? ? ? ? ? ? ? ? ? ? String password = sc.next(); ? ? ? ? ? ? ? ? ? ? ? if (password.equals(list.get(index).getPassword())){//如果輸入的卡號(hào)的索引index與該索引下的密碼一致則登錄成功 ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("萬(wàn)和" + list.get(index).getUsername() +"貴賓,歡迎您進(jìn)入系統(tǒng),您的卡號(hào):" + list.get(index).getId()); ? ? ? ? ? ? ? ? ? ? ? ? System.out.println(); ? ? ? ? ? ? ? ? ? ? ? ? ? while(true){//卡號(hào)密碼成功,進(jìn)入用戶界面 ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("==========歡迎您進(jìn)入萬(wàn)和銀行用戶操作界面=========="); ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("1 ? 查詢"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("2 ? 存款"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("3 ? 取款"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("4 ? 轉(zhuǎn)賬"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("5 ? 修改密碼"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("6 ? 退出"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("7 ? 注銷(xiāo)當(dāng)前賬戶"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入您要輸入的功能"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? String choice = sc.next();//用戶輸入 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? switch (choice){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case "1": ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("==========歡迎您進(jìn)入萬(wàn)和銀行用戶詳情界面========="); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? querymessage(list, index);//查詢個(gè)人信息方法 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case "2": ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("==========歡迎您進(jìn)入萬(wàn)和銀行用戶存款界面========="); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? inmoney(list, sc, index); //存款 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case "3": ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("==========歡迎您進(jìn)入萬(wàn)和銀行用戶取款界面========="); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? outmoney(list, sc, index); //取款 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case "4": ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("==========歡迎您進(jìn)入萬(wàn)和銀行用戶轉(zhuǎn)賬界面========="); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? transfer(list, sc, index);//轉(zhuǎn)賬功能 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case "5": ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("==========歡迎您進(jìn)入萬(wàn)和銀行用戶密碼修改界面========="); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? revisePassword(list, sc, index);//修改密碼 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case "6": ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("退出"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return;//結(jié)束整個(gè)方法,回到主界面 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case "7"://用戶注銷(xiāo) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("==========歡迎您進(jìn)入萬(wàn)和銀行用戶注銷(xiāo)界面========="); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("您確定要注銷(xiāo)該賬戶?"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("1 ? 確定"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("按任意鍵返回上一頁(yè)"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入您要輸入的選項(xiàng)"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? String choice0 = sc.next(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? switch (choice0){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case "1": ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Account ac = list.get(index); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? while(true){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入當(dāng)前賬戶的密碼"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? String key = sc.next(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (key.equals(ac.getPassword())){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? list.remove(index); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("注銷(xiāo)成功,將返回主界面"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? default: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? }else ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("您輸入的密碼有誤,請(qǐng)確認(rèn)"); ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? }
轉(zhuǎn)賬功能
//轉(zhuǎn)賬功能 private static void transfer(ArrayList<Account> list, Scanner sc, int index) { ? ?Account acc = list.get(index);//將集合list在index索引下的數(shù)據(jù)傳入acc ? ? ? ? int num = list.size();//獲取集合長(zhǎng)度 ? ? ? ? if(num < 2){//如果集合長(zhǎng)度小于二,不能轉(zhuǎn)賬 ? ? ? ? ? ? System.out.println("當(dāng)前系統(tǒng)不足兩個(gè),不能轉(zhuǎn)賬"); ? ? ? ? }else{ ? ? ? ? ? ? if(acc.getBalance() < 100){//余額小于100,不能轉(zhuǎn)賬 ? ? ? ? ? ? ? ? System.out.println("余額不足"); ? ? ? ? ? ? }else { ? ? ? ? ? ? ? ? while(true){ ? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入要轉(zhuǎn)賬的賬號(hào)"); ? ? ? ? ? ? ? ? ? ? String anotherId = sc.next(); ? ? ? ? ? ? ? ? ? ? int anotherIdIndex = getIndex(list,anotherId);//判斷賬號(hào)在系統(tǒng)中是否存在 ? ? ? ? ? ? ? ? ? ? if (anotherIdIndex == -1){//如果返回-1,不存在 ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("您輸入的賬戶不存在,請(qǐng)重新確認(rèn)"); ? ? ? ? ? ? ? ? ? ? }else{ ? ? ? ? ? ? ? ? ? ? ? ? Account acc1 = list.get(anotherIdIndex);//將剛剛輸入的索引下的數(shù)據(jù)傳入acc1,留作接下來(lái)修改 ? ? ? ? ? ? ? ? ? ? ? ? String name = acc1.getUsername(); ? ? ? ? ? ? ? ? ? ? ? ? char firstName = name.charAt(0);//獲取用戶名的姓氏 ? ? ? ? ? ? ? ? ? ? ? ? String xname = name.replace(firstName,'*');//將用戶名的姓氏變?yōu)?輸出 ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("您當(dāng)前要為" + xname + "轉(zhuǎn)賬"); ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)您輸入姓氏確認(rèn):"); ? ? ? ? ? ? ? ? ? ? ? ? String ?firstname = sc.next(); ? ? ? ? ? ? ? ? ? ? ? ? char chr = firstname.charAt(0);//輸入的姓氏和系統(tǒng)的姓氏對(duì)比 ? ? ? ? ? ? ? ? ? ? ? ?if(chr == firstName){//如果相等,都是char形式才能比較 ? ? ? ? ? ? ? ? ? ? ? ? ? ?System.out.println("輸入正確"); ? ? ? ? ? ? ? ? ? ? ? ? ? ?while(true){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?System.out.println("請(qǐng)輸入要轉(zhuǎn)入的金額:"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?double sendmoney = sc.nextDouble(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if(sendmoney < list.get(index).getEnchashment()){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?System.out.println("您當(dāng)前轉(zhuǎn)賬超過(guò)了當(dāng)次限額!"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?else if(sendmoney > list.get(index).getBalance()){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?System.out.println("您的余額不足"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}else{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?acc.setBalance(list.get(index).getBalance() - sendmoney);//對(duì)自己的金額扣錢(qián) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?acc.setBalance(list.get(anotherIdIndex).getBalance() + sendmoney);//對(duì)別人的賬戶打款 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?System.out.println("轉(zhuǎn)賬成功"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?return; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? }
修改密碼
//修改密碼 private static void revisePassword(ArrayList<Account> list, Scanner sc, int index) { ? ?Account acc = list.get(index); ? ? ? ? while (true){ ? ? ? ? ? ? System.out.println("請(qǐng)您輸入當(dāng)前賬戶密碼:"); ? ? ? ? ? ? String nowpassword = sc.next(); ? ? ? ? ? ? if (nowpassword.equals(acc.getPassword())){//看原來(lái)的密碼是否輸入正確 ? ? ? ? ? ? ? ? System.out.println("請(qǐng)您輸入新的密碼:"); ? ? ? ? ? ? ? ? String newpassword = sc.next(); ? ? ? ? ? ? ? ? list.get(index).setPassword(newpassword);//set功能將新的密碼寫(xiě)入系統(tǒng) ? ? ? ? ? ? ? ? System.out.println("密碼修改成功請(qǐng)您重新登錄"); ? ? ? ? ? ? ? ? return; ? ? ? ? ? ? }else{ ? ? ? ? ? ? ? ? System.out.println("當(dāng)前賬戶密碼不正確"); ? ? ? ? ? ? } ? ? ? ? } ? ? }
取款
//取款 private static void outmoney(ArrayList<Account> list, Scanner sc, int index) { ? ?Account acc = list.get(index); ? ? ? ? if (list.get(index).getBalance() < 100){ ? ? ? ? ? ? System.out.println("余額不足100元,無(wú)法取出,請(qǐng)存入金額!"); ? ? ? ? }else{ ? ? ? ? ? ? while(true){ ? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入取款的金額"); ? ? ? ? ? ? ? ? double outmoney = sc.nextDouble(); ? ? ? ? ? ? ? ? ? if(outmoney < list.get(index).getEnchashment()){ ? ? ? ? ? ? ? ? ? ? System.out.println("您當(dāng)前取款超過(guò)了當(dāng)次限額!"); ? ? ? ? ? ? ? ? }else if(list.get(index).getBalance()- outmoney < 0){ ? ? ? ? ? ? ? ? ? ? System.out.println("您的賬戶余額不足"); ? ? ? ? ? ? ? ? }else{ ? ? ? ? ? ? ? ? ? ? acc.setBalance(list.get(index).getBalance() - outmoney); ? ? ? ? ? ? ? ? ? ? System.out.println("您已取款成功!"); ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? }
查詢個(gè)人信息方法
//查詢個(gè)人信息方法 ? ? private static void querymessage(ArrayList<Account> list, int index) { ? ? ? ? System.out.println("您的賬戶信息如下:"); ? ? ? ? for (int i1 = 0; i1 < list.size(); i1++) {//遍歷 ? ? ? ? ? ? Account acc = list.get(index);//將數(shù)據(jù)導(dǎo)進(jìn)來(lái) ? ? ? ? ? ? System.out.println("卡號(hào):" + acc.getId()); ? ? ? ? ? ? System.out.println("姓名:" + acc.getUsername()); ? ? ? ? ? ? System.out.println("余額:" + acc.getBalance()); ? ? ? ? ? ? System.out.println("當(dāng)次取現(xiàn)額度:" + acc.getEnchashment()); ? ? ? ? } ? ? }
存款
//存款 ? ? private static void inmoney(ArrayList<Account> list, Scanner sc, int index) { ? ? ? ? System.out.println("請(qǐng)您輸入存款的金額"); ? ? ? ? double inmoney = sc.nextDouble(); ? ? ? ? Account acc = list.get(index); ? ? ? ? acc.setBalance(list.get(index).getBalance() + inmoney) ;//集合list中的值為index的索引下的余額balance 加 剛剛存入的金額inmoney ? ? ? ? System.out.println("您已經(jīng)存款成功"); ? ? }
2、用戶開(kāi)戶功能
// 2、用戶開(kāi)戶功能 public static void register(ArrayList<Account> list){ ? ? ? ? Scanner sc = new Scanner(System.in); ? ? ? ? ? System.out.println("請(qǐng)您輸入您的姓名:"); ? ? ? ? String username = sc.next(); ? ? ? ? ? String password; ? ? ? ? while(true){ ? ? ? ? ? ? System.out.println("請(qǐng)您輸入您的密碼:"); ? ? ? ? ? ? String password1 = sc.next(); ? ? ? ? ? ? System.out.println("請(qǐng)您再次確認(rèn)密碼:"); ? ? ? ? ? ? String password2 = sc.next(); ? ? ? ? ? ? if (password1.equals(password2)){ ? ? ? ? ? ? ? ? password = password2; ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? }else{ ? ? ? ? ? ? ? ? System.out.println("兩次密碼不一致,請(qǐng)重新輸入"); ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? System.out.println(password); ? ? ? ? ? System.out.println("請(qǐng)?jiān)O(shè)置當(dāng)日取現(xiàn)額度:"); ? ? ? ? double enchashment = sc.nextDouble(); ? ? ? ? ? //自動(dòng)生成八位數(shù)卡號(hào)并檢測(cè)是否重復(fù) ? ? ? ? Random r = new Random(); ? ? ? ? String s = new String(); ? ? ? ? while(true) { ? ? ? ? ? ? for (int i = 0; i < 8; i++) { ? ? ? ? ? ? ? ? int num = r.nextInt(10); ? ? ? ? ? ? ? ? s += num; ? ? ? ? ? ? } ? ? ? ? ? ? int index = getIndex(list, s);//調(diào)用getIndex方法返回-1則沒(méi)有重復(fù) ? ? ? ? ? ? if (index == -1){ ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? ? //設(shè)置賬戶余額 ? ? ? ? double balance = 0; ? ? ? ? Account acc = new Account(s,username,enchashment,password,balance); ? ? ? ? list.add(acc); ? ? ? ? System.out.println("萬(wàn)和" + username + "貴賓,您的賬戶已經(jīng)開(kāi)卡成功,您的卡號(hào)是:" + s); ? ? ? ? }
//獲取集合中的用戶的索引and判斷集合中是否有該對(duì)象 private static int getIndex(ArrayList<Account> list, String s) { ? ? ? ? int index = -1;//假設(shè)新生成的卡號(hào),在集合中不存在 ? ? ? ? for (int i = 0; i < list.size(); i++) {//遍歷集合,獲取每一個(gè)對(duì)象,準(zhǔn)備進(jìn)行查找 ? ? ? ? ? ? Account ac = list.get(i);//類名 對(duì)象名 = 集合名.get(i); ? ? ? ? ? ? String idcard = ac.getId();//獲取每一個(gè)對(duì)象的學(xué)號(hào)叫id ? ? ? ? ? ? if(idcard.equals(s)){//判斷獲取過(guò)的id和新生成的s是否一樣,如果相同賦值給index ? ? ? ? ? ? ? ? index = i;//存在,讓index變量記錄對(duì)象的索引值 ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? return index; ? ? } ? ? //查看信息(后臺(tái)統(tǒng)計(jì)) ? ? public static void htlook(ArrayList<Account> list){ ? ? ? ? for (int i = 0; i < list.size(); i++) { ? ? ? ? ? ? Account acc = list.get(i); ? ? ? ? ? ? System.out.println(acc.getId()+" ? ?" + acc.getEnchashment() + " ? " + acc.getUsername() + " ? ?" + acc.getPassword() + " ? " + acc.getBalance()); ? ? ? ? } ? ? } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java實(shí)現(xiàn)ATM銀行管理系統(tǒng)(控制臺(tái)版本)
- java模擬實(shí)現(xiàn)銀行ATM機(jī)操作
- Java實(shí)現(xiàn)簡(jiǎn)單控制臺(tái)版ATM系統(tǒng)
- Java實(shí)現(xiàn)ATM機(jī)操作系統(tǒng)
- Java實(shí)現(xiàn)基礎(chǔ)銀行ATM系統(tǒng)
- Java基于控制臺(tái)界面實(shí)現(xiàn)ATM系統(tǒng)
- Java簡(jiǎn)單實(shí)現(xiàn)銀行ATM系統(tǒng)
- java實(shí)現(xiàn)簡(jiǎn)單銀行ATM系統(tǒng)
- Java詳解實(shí)現(xiàn)ATM機(jī)模擬系統(tǒng)
相關(guān)文章
SpringBoot實(shí)現(xiàn)整合微信支付方法詳解
這篇文章主要介紹了SpringBoot實(shí)現(xiàn)整合微信支付的過(guò)程詳解,文中的示例代碼對(duì)我們的工作或?qū)W習(xí)有一定的幫助,感興趣的小伙伴可以跟隨小編學(xué)習(xí)一下2021-12-12指定springboot的jar運(yùn)行內(nèi)存方式
這篇文章主要介紹了指定springboot的jar運(yùn)行內(nèi)存方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02基于RxPaparazzo實(shí)現(xiàn)圖片裁剪、圖片旋轉(zhuǎn)、比例放大縮小功能
這篇文章主要為大家詳細(xì)介紹了基于RxPaparazzo實(shí)現(xiàn)圖片裁剪、圖片旋轉(zhuǎn)、比例放大縮小功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05Springboot+Mybatis-plus不使用SQL語(yǔ)句進(jìn)行多表添加操作及問(wèn)題小結(jié)
這篇文章主要介紹了在Springboot+Mybatis-plus不使用SQL語(yǔ)句進(jìn)行多表添加操作,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04Java實(shí)戰(zhàn)之校園外賣(mài)點(diǎn)餐系統(tǒng)的實(shí)現(xiàn)
這篇文章主要介紹了如何利用Java實(shí)現(xiàn)簡(jiǎn)易的校園外賣(mài)點(diǎn)餐系統(tǒng),文中采用的技術(shù)有:JSP、Spring、SpringMVC、MyBatis 等,感興趣的可以了解一下2022-03-03spring?data?jpa查詢一個(gè)實(shí)體類的部分屬性方式
這篇文章主要介紹了spring?data?jpa查詢一個(gè)實(shí)體類的部分屬性方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02