How to realize simple Bank Management system by java
This article mainly introduces java how to achieve a simple bank management system, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
The details are as follows
Account class
Package Account; public abstract class Account {private int id;// account private String password;// password private String name;// name private String personId;// ID card number private String email;// mailbox private double ceiling;// loan attribute private static double balance;// account 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 = personId; this.email = email;} public Account (int id, String password) {this.id = id; this.password = password;} / / account opening function public Account openAccount () {return null } / / shows the information function public void show () {System.out.println ("account ID:" + id + "password:" + password + "name:" + name + "ID card number:" + email ");} / / login function public void enter () {} / / withdrawal method is abstract method public abstract void deposit (double money) / Deposit method public static void withdraw (double money) {balance = balance + money; System.out.println ("you have deposited" + money + "yuan, account balance is" + 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 class
Package Account; import java.util.Scanner; public class Bank {int iram / account No. Private Account [] account = new Account [100]; / / account object array private int accountNum = 0 Scanner sc / number of accounts private String password1;// account type private String password1;// confirmation password int id = 1000000 int / first account / constant control account + 1 Scanner sc = new Scanner (System.in) each time; int insert Public Bank () {} / / main interface public void mainView () {System.out.println ("* Welcome to login to the bank management system *"); System.out.println ("* Please select business *"); System.out.println ("* 1, create account *") System.out.println ("* 2, login account *");} / function selection function public void select () {int select = sc.nextInt (); switch (select) {case 1: this.openAccount (); break; case 2: this.enter (); break;} / / account opening function public Account openAccount () {System.out.println ("Please enter your name") String name = sc.next (); / / System.out.println ("Please enter your card number"); / / int id = sc.nextInt (); System.out.println ("Please enter your password"); String password = sc.next (); System.out.println ("Please reconfirm your password"); String password1 = sc.next () While (! password1.equals (password)) {System.out.println ("Sorry, please re-enter your password, please re-enter your password"); System.out.println ("Please re-enter your password"); password = sc.next (); System.out.println ("Please confirm your password"); password1 = sc.next ();} System.out.println ("Please enter your ID number"); String personId = sc.next () System.out.println ("Please enter your email address"); String email = sc.next (); System.out.println ("Please enter your account type"); System.out.println ("1, memory card 2, credit card"); type = sc.nextInt (); switch (type) {case 1: account [accountNum] = new LoanSavingAccount (100000 + j, password, name, personId, email, 0,0) / / create a memory card account object with an initial balance of 0, and the default loan amount is 0 yuan [accountNum] .show (); / / call System.out.println ("card type: memory card"); accountNum++; jackers; return account [accountNum]; case 2: account [accountNum] = new LoanCreditAccount (100000 + j, password, name, personId, email, 0, 0, 5000) / / create a credit card account object with one more transparent attribute, and the initial overfunded amount is 5000 CNY. [accountNum] .show (); / / call the function to display account information a System.out.println ("card type: credit card"); accountNum++; jackpot; return account [accountNum];} return null;} / / System.out.println ("Congratulations, you have successfully created the account!" + "your account name is" + account.getId () + / "your account type is" + type); / / return account; / / login function public Account enter () {System.out.println ("Please enter your bank card number"); int id = sc.nextInt (); System.out.println ("Please enter your password"); String password = sc.next () If (accountNum = = 0) {System.out.println ("unregistered account, please register first!") ; 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 ("you withdrew" + money + "money, your balance is" + super.getBalance ());} else System.out.println ("Sorry for your balance and insufficient overdraft!") ;} / @ Override// public void requestLoan () {/ TODO Auto-generated method stub//}} package Account; public interface General {void requestLoan (double money); / / loan method void payLoan (double money); / / repayment / / void getLoan (); / / get total user amount}
Credit card subcategory
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) {/ / loan method if (0