您好,登錄后才能下訂單哦!
本篇內容介紹了“java如何實現銀行管理系統”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
銀行管理系統 (java實現),供大家參考,具體內容如下
1.創建一個封裝類(Studentss)
import javax.naming.Name;import javax.naming.NamingEnumeration; public class Studentss {//無參public Studentss(){}//有參public Studentss(String name,String account,int balance,String uesrpwds,String card){ super(); this.name=name; this.account=account; this.balance=balance; this.uesrpwds=uesrpwds; this.card=card;}//修改public Studentss(String name,String account,int balance,String uesrpwds,String card,int id){ super(); this.name=name; this.account=account; this.balance=balance; this.uesrpwds=uesrpwds; this.card=card; this.id = id;}//定義一個數據類封裝private String name;//名字private String account;//賬號private int balance;//余額private String uesrpwds;//密碼private String card;//身份證號private int id;//編號//封裝idpublic int getId(){ return id;}public void setId(int id) { this.id = id;}//封裝名字getpublic String getName(){ return name;} public void setName(String name) { this.name = name;}//封裝賬號getpublic String getAccount(){ return account;}public void setAccount(String account) { this.account = account;}//封裝余額getpublic int getBalance() { return balance;}public void setBalance(int balance) { this.balance = balance;}//封裝密碼getpublic String getUesrpwds() { return uesrpwds;}public void setUesrpwds(String uesrpwds) { this.uesrpwds = uesrpwds;}//封裝身份證getpublic String getCard() { return card;}//set身份證public void setCard(String card) { this.card = card;}@Overridepublic String toString() { return super.toString();}}
2.實現增刪改查等效果 main方法(DoemTest)
import com.sun.org.apache.xpath.internal.objects.XObject;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Scanner;public class DoemTest{public static ArrayList<Studentss> list =new ArrayList<>();//聲明數組public static void main(String[] args) { Scanner sc = new Scanner(System.in); //初始化兩個數據 Studentss studentss = new Studentss(); studentss.setName("張穎穎"); studentss.setAccount("17908064359"); studentss.setBalance(2000); studentss.setUesrpwds("4321"); studentss.setCard("510010619891231127"); list.add(studentss);//初始化數組 添加值 Studentss studentss1 = new Studentss(); studentss1.setName("劉華"); studentss1.setAccount("17908064368"); studentss1.setBalance(8000); studentss1.setUesrpwds("4567"); studentss1.setCard("410207198904051271"); list.add(studentss1);//初始化數組 添加值 // this.list =new ArrayList<>(); //String pass =input.lenth(); int input; //銀行增刪改查輸出 System.out.println("賬戶姓名:張穎穎 賬號: 17908064359 存款余額: 2000 密碼:4321 身份證號:510010619891231127"); System.out.println("賬戶姓名:劉華 賬號: 17908064368 存款余額: 8000 密碼:4567 身份證號:410207198904051271"); do { System.out.println("=====================歡迎使用知道銀行服務===================="); System.out.println("1:開戶 2:存款 3: 取款 4: 轉賬 5:查余額 6:修改密碼 0:退出"); System.out.println("==========================================================="); //判斷輸出選項 Scanner set = new Scanner(System.in);//接受輸入的值(0~6); input =set.nextInt(); switch (input){ case 1://開戶 Openaccount(list); break; case 2://存款 CunKuang(list); break; case 3://取款 Qukuang(list); break; case 4://轉賬 Zhuangzhang(list); break; case 5://查詢余額 Chaxun(list); break; case 6://修改密碼 Changethepassword(list); break; case 0://退出 System.out.println("謝謝使用!"); break; default: System.out.println("請輸入指定的命令語句!"); break; } }while (input != 0);}//開戶public static void Openaccount(ArrayList<Studentss> list){ Studentss studentss =new Studentss(); int RDnum=(int)((Math.random()*9+1)*1000);//定義數據數 Scanner sc=new Scanner(System.in); System.out.println("請輸入用戶名:"); String name = sc.next(); studentss.setName(name);//接收輸出 //list.add(studentss.getName());//存儲數據 System.out.println("請輸入賬號密碼:"); String uesrpwds=sc.next(); studentss.setUesrpwds(uesrpwds);//接收輸出 //list.add(studentss.getUesrpwds());//存儲數據 System.out.println("請輸入身份證號:"); String card= sc.next(); studentss.setCard(card);//接收輸出 //list.add(studentss.getCard());//存儲數據 System.out.println("請輸入金額:"); int balance=sc.nextInt(); studentss.setBalance(balance);//接收輸出 //list.add(studentss.getBalance());//存儲數據 String account="1790806"+RDnum; //賬號: studentss.setAccount(account);//接收輸出 //list.add(studentss.getAccount());//存儲數據 System.out.println("賬號:"+account); System.out.println("賬號名:"+name); System.out.println("余額:"+balance); System.out.println("創建成功!"); list.add(studentss); } //查詢金額 public static void Chaxun(ArrayList<Studentss> list) { Scanner cx2 = new Scanner(System.in); System.out.println("請輸入賬號:"); String account = cx2.next(); System.out.println("請輸入賬號密碼:"); Scanner mc2 = new Scanner(System.in); String uesrpwds = cx2.next(); Iterator<Studentss> iterator = list.iterator(); while (iterator.hasNext()) {//判斷是否存在下一個對象元素 Studentss studentss = (Studentss) iterator.next();//獲取下一元素 if (account.equals(studentss.getAccount()) && uesrpwds.equals(studentss.getUesrpwds())) { System.out.println("賬號的金額為:" + studentss.getBalance()); break; } } }//存款public static void CunKuang(ArrayList<Studentss> list){ //對象 // Studentss studentss= new Studentss(); System.out.println("請輸入賬號:"); Scanner cx = new Scanner(System.in); String account =cx.next(); Iterator<Studentss> iterator = list.iterator(); while (iterator.hasNext()){ Studentss studentss =(Studentss) iterator.next(); if (account.equals(studentss.getAccount())){ System.out.println("請輸入存款金額:"); Scanner cxc =new Scanner(System.in); int num = cxc.nextInt(); if (num >= 0) { studentss.setBalance(studentss.getBalance()+num); System.out.println("存款成功!余額為:"+studentss.getBalance()); break; }else { System.out.println("存款失敗!余額為:"+studentss.getBalance()); break; } } else { } if(iterator.hasNext() ==false){ System.out.println("查無賬號!"); }}}//取款public static void Qukuang(ArrayList<Studentss> list){ Scanner cx = new Scanner(System.in); System.out.println("請輸入賬號:"); String account =cx.next(); Scanner mc = new Scanner(System.in); System.out.println("請輸入賬號密碼:"); String uesrpwds =mc.next(); //迭代器 Iterator<Studentss> iterator = list.iterator(); while (iterator.hasNext()){//判斷是否存在下一個對象元素 Studentss studentss =(Studentss) iterator.next();//獲取下一元素 //判斷密碼賬號是否存在相等 if(account.equals(studentss.getAccount())&&uesrpwds.equals(studentss.getUesrpwds())) { System.out.println("請輸入取款金額:"); Scanner mcx =new Scanner(System.in); int mic =mcx.nextInt(); studentss.setBalance(studentss.getBalance()-mic); if (mic>studentss.getBalance()){ System.out.println("取款失敗!"); }else { System.out.println("取款成功!余額為:"+studentss.getBalance()); } break; }else { if(iterator.hasNext() ==false){ System.out.println("賬號或者密碼不存在!"); } } }}//轉賬public static void Zhuangzhang(ArrayList list){ Scanner input = new Scanner(System.in);// 賦值一個輸入值 System.out.println("請輸入轉出賬號:"); String account =input.next(); System.out.println("請輸入轉出賬戶密碼:"); String pwd1=input.next(); System.out.println("請輸入轉入賬號:"); String account1=input.next(); //迭代器 Iterator<Studentss> iterator=list.iterator(); while (iterator.hasNext()){ Studentss studentss=iterator.next(); //判斷轉出賬戶是否存在 if (account.equals(studentss.getAccount())&&pwd1.equals(studentss.getUesrpwds()) ) { System.out.println("請輸入轉出金額"); int moneys=input.nextInt(); //判斷轉出賬戶金額是否大于或小于所需要金額 if (studentss.getBalance()>=moneys){ //迭代器在迭代一次 Iterator<Studentss> iterator1=list.iterator(); while (iterator1.hasNext()){ Studentss studentss1=iterator1.next(); //判斷轉入賬戶是否存在 if (account1.equals(studentss1.getAccount())&&account!=account1){ //滿足條件轉出賬戶扣除金額 studentss.setBalance(studentss.getBalance()-moneys); //滿足條件轉入賬戶存入金額 studentss1.setBalance(studentss1.getBalance()+moneys); System.out.println("轉賬成功,轉出賬號:" +studentss.getAccount()+ "轉出金額:" +studentss.getBalance() +"轉入賬號:" +studentss1.getAccount()+ "轉入金額" +studentss1.getBalance()); break; } } break; } else { System.out.println("轉賬失敗!余額為:"+studentss.getBalance()); } break; } else { if(iterator.hasNext()==false){ System.out.println("請輸入正確賬戶!"); } } }}//修改密碼public static void Changethepassword(ArrayList list){ System.out.println("請輸入賬號:"); Scanner cx = new Scanner(System.in); String account =cx.next(); System.out.println("請輸入賬號原密碼:"); Scanner mc = new Scanner(System.in); String uesrpwds =mc.next(); //迭代器 Iterator<Studentss> iterator = list.iterator(); while (iterator.hasNext()){//判斷是否存在下一個對象元素 Studentss studentss =(Studentss) iterator.next();//獲取下一元素 //判斷密碼賬號是否存在相等 if(account.equals(studentss.getAccount())&&uesrpwds.equals(studentss.getUesrpwds())) { Scanner mc1 = new Scanner(System.in); System.out.println("請輸入賬號新密碼:"); String uesrpwds1 =mc1.next(); Scanner mc2 = new Scanner(System.in); System.out.println("請再次輸入新密碼:"); String uesrpwds2 =mc2.next(); if (uesrpwds1.equals(uesrpwds2)) { studentss.setUesrpwds(uesrpwds1); System.out.println("賬號修改密碼成功!"); break; }else { System.out.println("兩次密碼不一樣"); break; } }else { if(iterator.hasNext()==false){ System.out.println("請輸入正確賬戶或密碼!"); } } }}}
“java如何實現銀行管理系統”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。