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;//编号 //封装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; } //封装账号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.实现增删改查等效果 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("请输入正确账户或密码!"); } } } } }
注:(我的代码可以有些的纰漏,问题不是很大,基本逻辑写的差不多了,如果有问题,评论下,我虚心请教,希望我们的代码之路会越走越远!加油)
关于管理系统的更多内容请点击《管理系统专题》进行学习
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
赞 (0)