java银行管理系统源码
银行管理系统(java实现),供大家参考,具体内容如下
1.创建一个封装类(Studentss)
importjavax.naming.Name; importjavax.naming.NamingEnumeration; publicclassStudentss{ //无参 publicStudentss(){} //有参 publicStudentss(Stringname,Stringaccount,intbalance,Stringuesrpwds,Stringcard){ super(); this.name=name; this.account=account; this.balance=balance; this.uesrpwds=uesrpwds; this.card=card; } //修改 publicStudentss(Stringname,Stringaccount,intbalance,Stringuesrpwds,Stringcard,intid){ super(); this.name=name; this.account=account; this.balance=balance; this.uesrpwds=uesrpwds; this.card=card; this.id=id; } //定义一个数据类封装 privateStringname;//名字 privateStringaccount;//账号 privateintbalance;//余额 privateStringuesrpwds;//密码 privateStringcard;//身份证号 privateintid;//编号 //封装id publicintgetId(){ returnid; } publicvoidsetId(intid){ this.id=id; } //封装名字get publicStringgetName(){ returnname; } publicvoidsetName(Stringname){ this.name=name; } //封装账号get publicStringgetAccount(){ returnaccount; } publicvoidsetAccount(Stringaccount){ this.account=account; } //封装余额get publicintgetBalance(){ returnbalance; } publicvoidsetBalance(intbalance){ this.balance=balance; } //封装密码get publicStringgetUesrpwds(){ returnuesrpwds; } publicvoidsetUesrpwds(Stringuesrpwds){ this.uesrpwds=uesrpwds; } //封装身份证get publicStringgetCard(){ returncard; } //set身份证 publicvoidsetCard(Stringcard){ this.card=card; } @Override publicStringtoString(){ returnsuper.toString(); } }
2.实现增删改查等效果main方法(DoemTest)
importcom.sun.org.apache.xpath.internal.objects.XObject; importjava.util.ArrayList; importjava.util.Iterator; importjava.util.List; importjava.util.Scanner; publicclassDoemTest{ publicstaticArrayListlist=newArrayList<>();//声明数组 publicstaticvoidmain(String[]args){ Scannersc=newScanner(System.in); //初始化两个数据 Studentssstudentss=newStudentss(); studentss.setName("张颖颖"); studentss.setAccount("17908064359"); studentss.setBalance(2000); studentss.setUesrpwds("4321"); studentss.setCard("510010619891231127"); list.add(studentss);//初始化数组添加值 Studentssstudentss1=newStudentss(); studentss1.setName("刘华"); studentss1.setAccount("17908064368"); studentss1.setBalance(8000); studentss1.setUesrpwds("4567"); studentss1.setCard("410207198904051271"); list.add(studentss1);//初始化数组添加值 //this.list=newArrayList<>(); //Stringpass=input.lenth(); intinput; //银行增删改查输出 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("==========================================================="); //判断输出选项 Scannerset=newScanner(System.in);//接受输入的值(0~6); input=set.nextInt(); switch(input){ case1://开户 Openaccount(list); break; case2://存款 CunKuang(list); break; case3://取款 Qukuang(list); break; case4://转账 Zhuangzhang(list); break; case5://查询余额 Chaxun(list); break; case6://修改密码 Changethepassword(list); break; case0://退出 System.out.println("谢谢使用!"); break; default: System.out.println("请输入指定的命令语句!"); break; } }while(input!=0); } //开户 publicstaticvoidOpenaccount(ArrayList list){ Studentssstudentss=newStudentss(); intRDnum=(int)((Math.random()*9+1)*1000);//定义数据数 Scannersc=newScanner(System.in); System.out.println("请输入用户名:"); Stringname=sc.next(); studentss.setName(name);//接收输出 //list.add(studentss.getName());//存储数据 System.out.println("请输入账号密码:"); Stringuesrpwds=sc.next(); studentss.setUesrpwds(uesrpwds);//接收输出 //list.add(studentss.getUesrpwds());//存储数据 System.out.println("请输入身份证号:"); Stringcard=sc.next(); studentss.setCard(card);//接收输出 //list.add(studentss.getCard());//存储数据 System.out.println("请输入金额:"); intbalance=sc.nextInt(); studentss.setBalance(balance);//接收输出 //list.add(studentss.getBalance());//存储数据 Stringaccount="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); } //查询金额 publicstaticvoidChaxun(ArrayList list){ Scannercx2=newScanner(System.in); System.out.println("请输入账号:"); Stringaccount=cx2.next(); System.out.println("请输入账号密码:"); Scannermc2=newScanner(System.in); Stringuesrpwds=cx2.next(); Iterator iterator=list.iterator(); while(iterator.hasNext()){//判断是否存在下一个对象元素 Studentssstudentss=(Studentss)iterator.next();//获取下一元素 if(account.equals(studentss.getAccount())&& uesrpwds.equals(studentss.getUesrpwds())){ System.out.println("账号的金额为:"+studentss.getBalance()); break; } } } //存款 publicstaticvoidCunKuang(ArrayList list){ //对象 //Studentssstudentss=newStudentss(); System.out.println("请输入账号:"); Scannercx=newScanner(System.in); Stringaccount=cx.next(); Iterator iterator=list.iterator(); while(iterator.hasNext()){ Studentssstudentss=(Studentss)iterator.next(); if(account.equals(studentss.getAccount())){ System.out.println("请输入存款金额:"); Scannercxc=newScanner(System.in); intnum=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("查无账号!"); } } } //取款 publicstaticvoidQukuang(ArrayList list){ Scannercx=newScanner(System.in); System.out.println("请输入账号:"); Stringaccount=cx.next(); Scannermc=newScanner(System.in); System.out.println("请输入账号密码:"); Stringuesrpwds=mc.next(); //迭代器 Iterator iterator=list.iterator(); while(iterator.hasNext()){//判断是否存在下一个对象元素 Studentssstudentss=(Studentss)iterator.next();//获取下一元素 //判断密码账号是否存在相等 if(account.equals(studentss.getAccount())&&uesrpwds.equals(studentss.getUesrpwds())) { System.out.println("请输入取款金额:"); Scannermcx=newScanner(System.in); intmic=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("账号或者密码不存在!"); } } } } //转账 publicstaticvoidZhuangzhang(ArrayListlist){ Scannerinput=newScanner(System.in);//赋值一个输入值 System.out.println("请输入转出账号:"); Stringaccount=input.next(); System.out.println("请输入转出账户密码:"); Stringpwd1=input.next(); System.out.println("请输入转入账号:"); Stringaccount1=input.next(); //迭代器 Iterator iterator=list.iterator(); while(iterator.hasNext()){ Studentssstudentss=iterator.next(); //判断转出账户是否存在 if(account.equals(studentss.getAccount())&&pwd1.equals(studentss.getUesrpwds())){ System.out.println("请输入转出金额"); intmoneys=input.nextInt(); //判断转出账户金额是否大于或小于所需要金额 if(studentss.getBalance()>=moneys){ //迭代器在迭代一次 Iterator iterator1=list.iterator(); while(iterator1.hasNext()){ Studentssstudentss1=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("请输入正确账户!"); } } } } //修改密码 publicstaticvoidChangethepassword(ArrayListlist){ System.out.println("请输入账号:"); Scannercx=newScanner(System.in); Stringaccount=cx.next(); System.out.println("请输入账号原密码:"); Scannermc=newScanner(System.in); Stringuesrpwds=mc.next(); //迭代器 Iterator iterator=list.iterator(); while(iterator.hasNext()){//判断是否存在下一个对象元素 Studentssstudentss=(Studentss)iterator.next();//获取下一元素 //判断密码账号是否存在相等 if(account.equals(studentss.getAccount())&&uesrpwds.equals(studentss.getUesrpwds())) {Scannermc1=newScanner(System.in); System.out.println("请输入账号新密码:"); Stringuesrpwds1=mc1.next(); Scannermc2=newScanner(System.in); System.out.println("请再次输入新密码:"); Stringuesrpwds2=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("请输入正确账户或密码!"); } } } } }
注:(我的代码可以有些的纰漏,问题不是很大,基本逻辑写的差不多了,如果有问题,评论下,我虚心请教,希望我们的代码之路会越走越远!加油)
关于管理系统的更多内容请点击《管理系统专题》进行学习
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。