您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)java銀行管理系統(tǒng)的實(shí)現(xiàn),文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
1.創(chuàng)建一個(gè)封裝類(lèi)(Studentss)
import javax.naming.Name; import javax.naming.NamingEnumeration; public class Studentss { //無(wú)參 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; } //定義一個(gè)數(shù)據(jù)類(lèi)封裝 private String name;//名字 private String account;//賬號(hào) private int balance;//余額 private String uesrpwds;//密碼 private String card;//身份證號(hào) private int id;//編號(hào) //封裝id public int getId(){ return id; } public void setId(int id) { this.id = id; } //封裝名字get public String getName(){ return name; } public void setName(String name) { this.name = name; } //封裝賬號(hào)get public String getAccount(){ return account; } public void setAccount(String account) { this.account = account; } //封裝余額get public int getBalance() { return balance; } public void setBalance(int balance) { this.balance = balance; } //封裝密碼get public String getUesrpwds() { return uesrpwds; } public void setUesrpwds(String uesrpwds) { this.uesrpwds = uesrpwds; } //封裝身份證get public String getCard() { return card; } //set身份證 public void setCard(String card) { this.card = card; } @Override public String toString() { return super.toString(); } }
2.實(shí)現(xiàn)增刪改查等效果 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<>();//聲明數(shù)組 public static void main(String[] args) { Scanner sc = new Scanner(System.in); //初始化兩個(gè)數(shù)據(jù) Studentss studentss = new Studentss(); studentss.setName("張穎穎"); studentss.setAccount("17908064359"); studentss.setBalance(2000); studentss.setUesrpwds("4321"); studentss.setCard("510010619891231127"); list.add(studentss);//初始化數(shù)組 添加值 Studentss studentss1 = new Studentss(); studentss1.setName("劉華"); studentss1.setAccount("17908064368"); studentss1.setBalance(8000); studentss1.setUesrpwds("4567"); studentss1.setCard("410207198904051271"); list.add(studentss1);//初始化數(shù)組 添加值 // this.list =new ArrayList<>(); //String pass =input.lenth(); int input; //銀行增刪改查輸出 System.out.println("賬戶(hù)姓名:張穎穎 賬號(hào): 17908064359 存款余額: 2000 密碼:4321 身份證號(hào):510010619891231127"); System.out.println("賬戶(hù)姓名:劉華 賬號(hào): 17908064368 存款余額: 8000 密碼:4567 身份證號(hào):410207198904051271"); do { System.out.println("=====================歡迎使用知道銀行服務(wù)===================="); System.out.println("1:開(kāi)戶(hù) 2:存款 3: 取款 4: 轉(zhuǎn)賬 5:查余額 6:修改密碼 0:退出"); System.out.println("==========================================================="); //判斷輸出選項(xiàng) Scanner set = new Scanner(System.in);//接受輸入的值(0~6); input =set.nextInt(); switch (input){ case 1://開(kāi)戶(hù) Openaccount(list); break; case 2://存款 CunKuang(list); break; case 3://取款 Qukuang(list); break; case 4://轉(zhuǎn)賬 Zhuangzhang(list); break; case 5://查詢(xún)余額 Chaxun(list); break; case 6://修改密碼 Changethepassword(list); break; case 0://退出 System.out.println("謝謝使用!"); break; default: System.out.println("請(qǐng)輸入指定的命令語(yǔ)句!"); break; } }while (input != 0); } //開(kāi)戶(hù) public static void Openaccount(ArrayList<Studentss> list){ Studentss studentss =new Studentss(); int RDnum=(int)((Math.random()*9+1)*1000);//定義數(shù)據(jù)數(shù) Scanner sc=new Scanner(System.in); System.out.println("請(qǐng)輸入用戶(hù)名:"); String name = sc.next(); studentss.setName(name);//接收輸出 //list.add(studentss.getName());//存儲(chǔ)數(shù)據(jù) System.out.println("請(qǐng)輸入賬號(hào)密碼:"); String uesrpwds=sc.next(); studentss.setUesrpwds(uesrpwds);//接收輸出 //list.add(studentss.getUesrpwds());//存儲(chǔ)數(shù)據(jù) System.out.println("請(qǐng)輸入身份證號(hào):"); String card= sc.next(); studentss.setCard(card);//接收輸出 //list.add(studentss.getCard());//存儲(chǔ)數(shù)據(jù) System.out.println("請(qǐng)輸入金額:"); int balance=sc.nextInt(); studentss.setBalance(balance);//接收輸出 //list.add(studentss.getBalance());//存儲(chǔ)數(shù)據(jù) String account="1790806"+RDnum; //賬號(hào): studentss.setAccount(account);//接收輸出 //list.add(studentss.getAccount());//存儲(chǔ)數(shù)據(jù) System.out.println("賬號(hào):"+account); System.out.println("賬號(hào)名:"+name); System.out.println("余額:"+balance); System.out.println("創(chuàng)建成功!"); list.add(studentss); } //查詢(xún)金額 public static void Chaxun(ArrayList<Studentss> list) { Scanner cx2 = new Scanner(System.in); System.out.println("請(qǐng)輸入賬號(hào):"); String account = cx2.next(); System.out.println("請(qǐng)輸入賬號(hào)密碼:"); Scanner mc2 = new Scanner(System.in); String uesrpwds = cx2.next(); Iterator<Studentss> iterator = list.iterator(); while (iterator.hasNext()) {//判斷是否存在下一個(gè)對(duì)象元素 Studentss studentss = (Studentss) iterator.next();//獲取下一元素 if (account.equals(studentss.getAccount()) && uesrpwds.equals(studentss.getUesrpwds())) { System.out.println("賬號(hào)的金額為:" + studentss.getBalance()); break; } } } //存款 public static void CunKuang(ArrayList<Studentss> list){ //對(duì)象 // Studentss studentss= new Studentss(); System.out.println("請(qǐng)輸入賬號(hào):"); 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("請(qǐng)輸入存款金額:"); 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("查無(wú)賬號(hào)!"); } } } //取款 public static void Qukuang(ArrayList<Studentss> list){ Scanner cx = new Scanner(System.in); System.out.println("請(qǐng)輸入賬號(hào):"); String account =cx.next(); Scanner mc = new Scanner(System.in); System.out.println("請(qǐng)輸入賬號(hào)密碼:"); String uesrpwds =mc.next(); //迭代器 Iterator<Studentss> iterator = list.iterator(); while (iterator.hasNext()){//判斷是否存在下一個(gè)對(duì)象元素 Studentss studentss =(Studentss) iterator.next();//獲取下一元素 //判斷密碼賬號(hào)是否存在相等 if(account.equals(studentss.getAccount())&&uesrpwds.equals(studentss.getUesrpwds())) { System.out.println("請(qǐng)輸入取款金額:"); Scanner mcx =new Scanner(System.in); int mic =mcx.nextInt(); studentss.setBalance(studentss.getBalance()-mic); if (mic>studentss.getBalance()){ System.out.println("取款失?。?quot;); }else { System.out.println("取款成功!余額為:"+studentss.getBalance()); } break; }else { if(iterator.hasNext() ==false){ System.out.println("賬號(hào)或者密碼不存在!"); } } } } //轉(zhuǎn)賬 public static void Zhuangzhang(ArrayList list){ Scanner input = new Scanner(System.in);// 賦值一個(gè)輸入值 System.out.println("請(qǐng)輸入轉(zhuǎn)出賬號(hào):"); String account =input.next(); System.out.println("請(qǐng)輸入轉(zhuǎn)出賬戶(hù)密碼:"); String pwd1=input.next(); System.out.println("請(qǐng)輸入轉(zhuǎn)入賬號(hào):"); String account1=input.next(); //迭代器 Iterator<Studentss> iterator=list.iterator(); while (iterator.hasNext()){ Studentss studentss=iterator.next(); //判斷轉(zhuǎn)出賬戶(hù)是否存在 if (account.equals(studentss.getAccount())&&pwd1.equals(studentss.getUesrpwds()) ) { System.out.println("請(qǐng)輸入轉(zhuǎn)出金額"); int moneys=input.nextInt(); //判斷轉(zhuǎn)出賬戶(hù)金額是否大于或小于所需要金額 if (studentss.getBalance()>=moneys){ //迭代器在迭代一次 Iterator<Studentss> iterator1=list.iterator(); while (iterator1.hasNext()){ Studentss studentss1=iterator1.next(); //判斷轉(zhuǎn)入賬戶(hù)是否存在 if (account1.equals(studentss1.getAccount())&&account!=account1){ //滿(mǎn)足條件轉(zhuǎn)出賬戶(hù)扣除金額 studentss.setBalance(studentss.getBalance()-moneys); //滿(mǎn)足條件轉(zhuǎn)入賬戶(hù)存入金額 studentss1.setBalance(studentss1.getBalance()+moneys); System.out.println("轉(zhuǎn)賬成功,轉(zhuǎn)出賬號(hào):" +studentss.getAccount()+ "轉(zhuǎn)出金額:" +studentss.getBalance() +"轉(zhuǎn)入賬號(hào):" +studentss1.getAccount()+ "轉(zhuǎn)入金額" +studentss1.getBalance()); break; } } break; } else { System.out.println("轉(zhuǎn)賬失敗!余額為:"+studentss.getBalance()); } break; } else { if(iterator.hasNext()==false){ System.out.println("請(qǐng)輸入正確賬戶(hù)!"); } } } } //修改密碼 public static void Changethepassword(ArrayList list){ System.out.println("請(qǐng)輸入賬號(hào):"); Scanner cx = new Scanner(System.in); String account =cx.next(); System.out.println("請(qǐng)輸入賬號(hào)原密碼:"); Scanner mc = new Scanner(System.in); String uesrpwds =mc.next(); //迭代器 Iterator<Studentss> iterator = list.iterator(); while (iterator.hasNext()){//判斷是否存在下一個(gè)對(duì)象元素 Studentss studentss =(Studentss) iterator.next();//獲取下一元素 //判斷密碼賬號(hào)是否存在相等 if(account.equals(studentss.getAccount())&&uesrpwds.equals(studentss.getUesrpwds())) { Scanner mc1 = new Scanner(System.in); System.out.println("請(qǐng)輸入賬號(hào)新密碼:"); String uesrpwds1 =mc1.next(); Scanner mc2 = new Scanner(System.in); System.out.println("請(qǐng)?jiān)俅屋斎胄旅艽a:"); String uesrpwds2 =mc2.next(); if (uesrpwds1.equals(uesrpwds2)) { studentss.setUesrpwds(uesrpwds1); System.out.println("賬號(hào)修改密碼成功!"); break; }else { System.out.println("兩次密碼不一樣"); break; } }else { if(iterator.hasNext()==false){ System.out.println("請(qǐng)輸入正確賬戶(hù)或密碼!"); } } } } }
關(guān)于java銀行管理系統(tǒng)的實(shí)現(xiàn)就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。