现在的位置: 首页 > 编程语言 > 正文

java实现简单银行管理系统

2020年02月13日 编程语言 ⁄ 共 9840字 ⁄ 字号 评论关闭

本文实例为大家分享了java银行管理系统的具体代码,供大家参考,具体内容如下

账户类

package Account; public abstract class Account { private int id;//账号 private String password;//密码 private String name;//姓名 private String personId;//身份证号码 private String email;//邮箱 private double ceiling;//贷款属性 private static double balance;//账户余额 public Account() {} public Account(int id, String password, String name, String personId, String email, double balance,double ceiling) { super(); this.id = id; this.password = password; this.name = name; this.personId = personId; this.email = email; this.balance = balance; this.ceiling = ceiling; } public Account(int id, String password, String name, String personId, String email) { super(); this.id = id; this.password = password; this.name = name; this.personId = personId; this.email = email; } public Account(int id, String password) { this.id =id; this.password = password; } //开户函数 public Account openAccount() { return null; } //显示开户成功的信息函数 public void show() { System.out.println("账户ID为 : " + id + "密码为: " + password + "姓名为: " + name + "身份证号码为: " + personId + "邮箱为: " + email); } //登入函数 public void enter() { } //取款方法 为抽象方法 public abstract void deposit(double money); //存款方法 public static void withdraw(double money) { balance = balance + money; System.out.println("您已经存入" + money + "元,账户余额为" + balance ); }// public abstract void requestLoan(double money); public double getCeiling() { return ceiling; } public void setCeiling(double ceiling) { this.ceiling = ceiling; } public int getId() { return id; } public void setId( int id) { this.id = id; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPersonId() { return personId; } public void setPersonId(String personId) { this.personId = personId; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } }

Bank类

package Account; import java.util.Scanner; public class Bank { int i;// 账户编号 private Account[] account = new Account[100];// 账户对象数组 private int accountNum = 0;// 账户数量 private int type;// 账户类型 private String password1;// 确认密码 int id = 100000;//第一个开户账号 int j = 1;//常量控制开户账号每次+1 Scanner sc = new Scanner(System.in); int insert; public Bank() { } // 主界面 public void mainView() { System.out.println("******欢迎登入银行管理系统********"); System.out.println("******请选择业务***************"); System.out.println("******1、创建账户**************"); System.out.println("******2、登入账户**************"); } //功能选择函数 public void select() { int select = sc.nextInt(); switch(select) { case 1 : this.openAccount(); break; case 2 : this.enter(); break; } } // 开户函数 public Account openAccount() { System.out.println("请输入您的姓名"); String name = sc.next(); // System.out.println("请输入您的卡号"); // int id = sc.nextInt(); System.out.println("请输入您的密码"); String password = sc.next(); System.out.println("请再次确认您的密码"); String password1 = sc.next(); while (!password1.equals(password)) { System.out.println("对不起,两次输入的密码不一致,请重新输入"); System.out.println("请重新输入您的密码"); password = sc.next(); System.out.println("请再次确认您的密码"); password1 = sc.next(); } System.out.println("请输入您的身份证号码"); String personId = sc.next(); System.out.println("请输入您的邮箱"); String email = sc.next(); System.out.println("请输入您的账户类型"); System.out.println("1、存储卡 2、信用卡"); type = sc.nextInt(); switch (type) { case 1: account[accountNum] = new LoanSavingAccount(100000 + j, password, name, personId, email, 0, 0); // 创建存储卡账户对象,初始余额为0,默认贷款金额为0元 account[accountNum].show();//调用显示账户信息函数 System.out.println("卡类型为:存储卡"); accountNum++; j++; return account[accountNum]; case 2: account[accountNum] = new LoanCreditAccount(100000 + j, password, name, personId, email, 0, 0, 5000); // 创建信用卡账户对象,多一个透资属性,初始透资金额为5000元 account[accountNum].show();//调用显示账户信息函数a System.out.println("卡类型为: 信用卡"); accountNum++; j++; return account[accountNum]; } return null; } // System.out.println("恭喜您,创建账号成功啦!!!" + "您的账号名为"+ account.getId() + // "您的账户类型为" + type); // return account; // 登入函数 public Account enter() { System.out.println("请输入您的银行卡号"); int id = sc.nextInt(); System.out.println("请输入您的密码"); String password = sc.next(); if (accountNum == 0) { System.out.println("未注册账户,请先注册!"); this.openAccount(); this.mainView(); this.select(); } boolean flag = false; for (i = 0; i < accountNum; i++) { if (id == account[i].getId() && password.equals(account[i].getPassword())) {//判断Id和输入的账户密码是否一致 flag = true; break; } } if (!flag) { System.out.println("登入失败!!!"); } if (flag) { System.out.println("登入成功!!!!"); do { System.out.println("请选择业务"); System.out.println("******1、存款*****************"); System.out.println("******2、取款*****************"); System.out.println("******3、贷款*****************"); System.out.println("******4、还款*****************"); System.out.println("******3、按任意键退出*************"); insert = sc.nextInt(); switch(insert) { case 1 : System.out.println("******请输入存款金额*****************"); int money = sc.nextInt(); account[i].withdraw(money); break; case 2: System.out.println("******请输入取款金额*****************"); money = sc.nextInt(); account[i].deposit(money);//调用取款方法 break; case 3: judge(); break; case 4: repay(); break; } } while(insert == 1 || insert == 2 || insert == 3 || insert == 4); } return account[i]; } //存款方法 public void withdraw() { System.out.println("请输入存款金额"); int money = sc.nextInt(); account[i].withdraw(money); } //取款方法 public void deposit() { System.out.println("请输入取款金额"); int money = sc.nextInt(); account[i].deposit(200); } //计算银行余额总数方法 public void Accountsum() { double savSum = 0; for (int i = 0; i < accountNum; i++) { savSum += account[i].getBalance(); } } //判断是LoanSavingAccount 类还是LoacCreditAccount //贷款方法 public void judge() { System.out.println("******请输入贷款金额*****************"); int money = sc.nextInt(); if (account[accountNum - 1] instanceof LoanSavingAccount) { LoanSavingAccount a = (LoanSavingAccount) account[accountNum - 1]; a.requestLoan(money); }else { LoanCreditAccount b = (LoanCreditAccount) account[accountNum -1 ]; b.requestLoan(money); System.out.println("成功调用了贷款方法"); } } //还款方法 public void repay() { System.out.println("******请输入还款金额*****************"); int money = sc.nextInt(); if (account[accountNum - 1] instanceof LoanSavingAccount) {// System.out.println("判断过了1"); LoanSavingAccount a = (LoanSavingAccount) account[accountNum - 1]; a.payLoan(money); }else {// System.out.println("判断过了2"); LoanCreditAccount b1 = (LoanCreditAccount) account[accountNum - 1]; b1.payLoan(money); } } }

信用卡类

package Account; public class CreditAccount extends Account { //信用卡 private double overdraft;//透资属性 public CreditAccount() {} public CreditAccount(int id, String password, String name, String personId,String email, double balance, double ceiling, double overdraft) { super(id,password,name, personId, email, balance, ceiling); this.overdraft = overdraft;//多出一个透资属性 } // public void withdraw(double money) {// super.setBalance(super.getBalance() + money);// System.out.println("你的卡号为" + super.getId() +"的卡,您已经存入" + money + "元,账户余额为" + super.getBalance() );// } public void deposit(double money) {//信用卡取款方法 if ((super.getBalance() + overdraft) >= money) { super.setBalance(super.getBalance() - money) ; System.out.println("您取了" + money + "钱,您的余额为" + super.getBalance()); }else System.out.println("对不起您的余额和透支额度不足!"); } // @Override// public void requestLoan() {// // TODO Auto-generated method stub// // } } package Account; public interface General { void requestLoan(double money);//贷款方法 void payLoan(double money);//还款// void getLoan();//获取用户总额 }

信用卡子类

package Account; import java.util.Scanner; public class LoanCreditAccount extends CreditAccount implements General { Scanner sc = new Scanner(System.in); public LoanCreditAccount(){} public LoanCreditAccount(int id, String password, String name, String personId,String email, double balance, double ceiling,double overdraft) { super(id, password, name, personId, email, balance, ceiling, overdraft); } public void requestLoan(double money) {//贷款方法 if ( 0 <= money&& money <= 10000) {//贷款上限为10000 System.out.println("贷款成功,您的贷款金额为: " + money); System.out.println("您还能贷款的金额为: " + (10000 - money)); super.setCeiling(money);//把贷款的钱传给贷款属性 super.setBalance(super.getBalance() + money);//更新余额值 System.out.println("您现在的余额为: " + super.getBalance()); }else { System.out.println("对不起您的额度不够,贷款失败!"); } } public void payLoan(double money) {//还款 //三个判断条件:1. 还款金额小于等于贷款金额 2.还款金额小于所剩余额 3.还款金额大于0 if (super.getBalance() >= money && money <= super.getCeiling() && money >= 0) { super.setBalance(super.getBalance() - money); //更新余额 super.setCeiling(super.getCeiling() - money); System.out.println(" 您现在的余额为" + super.getBalance()); if (super.getCeiling() ==0) { System.out.println("您已经全部还清!!谢谢光临!!"); }else { System.out.println("您已经还了" + money +"您还需要还" + super.getCeiling() ); } }else { System.out.println("对不起,您的账户余额不足或者输入的还款额度超出范围!"); } } public void getLoan() {//获取用户贷款总额 double savSum = 0; }; }

package Account; import java.util.Scanner; import com_Day_7_11.SavingAccount; //存储卡子类public class LoanSavingAccount extends SavingAccount implements General{ Scanner sc = new Scanner(System.in); public LoanSavingAccount(int id, String password, String name, String personId, String email, double balance, double ceiling) { super(id, password, name, personId, email, balance, ceiling); } public void requestLoan(double money) {//贷款方法 if ( 0 <= money&& money <= 10000) {//贷款上限为10000 System.out.println("贷款成功,您的贷款金额为: " + money); System.out.println("您还能贷款的金额为: " + (10000 - money)); super.setCeiling(money);//把贷款的钱传给贷款属性 super.setBalance(super.getBalance() + money);//更新余额值 System.out.println("您现在的余额为: " + super.getBalance()); }else { System.out.println("对不起您的额度不够,贷款失败!"); } } public void payLoan(double money) {//还款 //三个判断条件:1. 还款金额小于等于贷款金额 2.还款金额小于所剩余额 3.还款金额大于0 if (super.getBalance() >= money && money <= super.getCeiling() && money >= 0) { super.setBalance(super.getBalance() - money); //更新余额 super.setCeiling(super.getCeiling() - money); System.out.println(" 您现在的余额为" + super.getBalance()); if (super.getCeiling() ==0) { System.out.println("您已经全部还清!!谢谢光临!!"); }else { System.out.println("您已经还了" + money +"您还需要还" + super.getCeiling() ); } }else { System.out.println("对不起,您的账户余额不足或者输入的还款额度超出范围!"); } } }

主界面测试函数

package Account; import java.util.Scanner; public class Text { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Bank b = new Bank(); while (true) { b.mainView();//调用界面函数 int select = sc.nextInt(); switch(select) { case 1: b.openAccount();//创建账户 break; case 2: b.enter();//登入 break; default: System.out.println("选择业务异常,请重新选择"); break; } System.out.println("是否继续选择其他业务"); System.out.println("退出请按 0"); System.out.println("继续选择其他业务请按 1"); select = sc.nextInt(); if (select == 0) { break; } } } }

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

本文标题: java实现简单银行管理系统

以上就上有关java实现简单银行管理系统的相关介绍,要了解更多java银行管理系统,java银行管理,java管理系统内容请登录学步园。

抱歉!评论已关闭.