This example for you to share the Java bank management system specific code, for your reference, the specific content is as follows
Accounts
package Account;
public abstract class Account {
Private int ID; // account number
Private string password; // password
Private string name; // name
Private String personId; // ID number
Private string email; // email
Private double ceiling; // loan attributes
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 = name;
this.personId = personId;
this.email = email;
}
public Account(int id, String password) {
this.id =id;
this.password = password;
}
//Account opening function
public Account openAccount() {
return null;
}
//Function to display the information of successful account opening
public void show() {
System.out.println ("account ID is: + + ID +" "password + + + + + + + + + name + name +" ID number is: + personId + "mailbox is:" + email); "ID" + "+" + "+ + +".
}
//Login function
public void enter() {
}
//The withdrawal method is abstract
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, and the 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 i; // account number
Private account [] account = new account [100]; // account object array
Private int accountnum = 0; // number of accounts
Private int type; // account type
Private string password1; // confirm password
Int id = 100000; // first account number
Int j = 1; // constant controls + 1 for each account opening
Scanner sc = new Scanner(System.in);
int insert;
public Bank() {
}
//Main interface
public void mainView() {
System.out.println ("* * * * * * * * * * * * * * * *");
System.out.println ("* * * * * * * * * * * * * * * * * * * * * *);
System.out.println ("* * * * * * * * * * * * * * * * * *");
System.out.println ("* * * * * * * * * * * * * * * * * * *");
}
//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 confirm your password again");
String password1 = sc.next();
while (!password1.equals(password)) {
System.out.println ("sorry, the two passwords are inconsistent, please re-enter");
System.out.println ("please re-enter your password");
password = sc.next();
System.out.println ("please confirm your password again");
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,
Personaid, email, 0, 0); // create a memory card account object with an initial balance of 0 and a default loan amount of 0 yuan
Account [accountnum]. Show(); // call the display account information function
System.out.println ("card type: memory card");
accountNum++;
j++;
return account[accountNum];
case 2:
account[accountNum] = new LoanCreditAccount(100000 + j, password, name,
Personaid, email, 0, 0, 5000); // create a credit card account object with one more asset penetration attribute. The initial penetration amount is 5000 yuan
Account [accountnum]. Show(); // call the display account information functiona
System.out.println ("card type: credit card");
accountNum++;
j++;
return account[accountNum];
}
return null;
}
// System.out.println "Congratulations, the account creation is successful!"!!! "+" 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()) {// judge whether the ID is consistent with the entered account password
flag = true;
break;
}
}
if (!flag) {
System.out.println ("login failed!"!!! ");
}
if (flag) {
System.out.println ("login successful!");
do {
System.out.println ("please select business");
System.out.println ("* * * * * * * * * * * * * * * * *");
System.out.println ("* * * * * * * * * * * * * * * * *");
System.out.println ("* * * * * * * * * * * * * * * * * *");
System.out.println (4. Repayment);
System.out.println (3. Press any key to exit);
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); // call the withdrawal method
break;
case 3: judge();
break;
case 4: repay();
break;
}
} while(insert == 1 || insert == 2 || insert == 3 || insert == 4);
}
return account[i];
}
//Deposit method
public void withdraw() {
System.out.println ("please enter deposit amount");
int money = sc.nextInt();
account[i].withdraw(money);
}
//Withdrawal method
public void deposit() {
System.out.println ("please enter the withdrawal amount");
int money = sc.nextInt();
account[i].deposit(200);
}
//How to calculate the total bank balance
public void Accountsum() {
double savSum = 0;
for (int i = 0; i < accountNum; i++) {
savSum += account[i].getBalance();
}
}
//Determine whether the class is loansavingaccount or loaccreditaccount
//Loan method
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 ("loan method called successfully");
}
}
//Repayment method
public void repay() {
System.out.println ("* * * * * * * * * * * * * * * * * *");
int money = sc.nextInt();
if (account[accountNum - 1] instanceof LoanSavingAccount) {
// System.out.println ("judged 1");
LoanSavingAccount a = (LoanSavingAccount) account[accountNum - 1];
a.payLoan(money);
}else {
// System.out.println ("judged 2");
LoanCreditAccount b1 = (LoanCreditAccount) account[accountNum - 1];
b1.payLoan(money);
}
}
}
Credit cards
package Account;
Public class creditaccount extensions account {// credit card
Private double overdraft; // asset penetration
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; // one more asset penetration attribute
}
// public void withdraw(double money) {
// super.setBalance(super.getBalance() + money);
// System.out.println ("your card number is"+ super.getId () + "card, you have deposited" + money + "yuan, account balance is"+ super.getBalance () );
// }
Public void deposit (double money) {// credit card withdrawal method
if ((super.getBalance() + overdraft) >= money) {
super.setBalance(super.getBalance() - money) ;
System.out.println ("you took" + money + "and your balance is"+ super.getBalance ());
}else System.out.println "Sorry, your balance and overdraft limit are not enough! ");
}
// @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 the total amount of users
}
Credit card
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 < = money & & money < = 10000) {// the loan limit is 10000
System.out.println ("loan successful, your loan amount is" + money ");
System.out.println ("the amount you can still borrow is: + (10000 - money));
super.setCeiling (money); // pass the loan money to the loan attribute
super.setBalance ( super.getBalance () + money); // update balance value
System.out.println (your current balance is:+ super.getBalance ());
}else {
System.out.println "Sorry, your amount is not enough, the loan failed! ");
}
}
Public void payloan (double money) {// repayment
//Three criteria: 1. The repayment amount is less than or equal to the loan amount; 2. The repayment amount is less than the remaining amount; 3. The repayment amount is greater than 0
if (super.getBalance() >= money && money <= super.getCeiling() && money >= 0) {
super.setBalance ( super.getBalance () - money); // update balance
super.setCeiling(super.getCeiling() - money);
System.out.println "Your current balance is"+ super.getBalance ());
if (super.getCeiling() ==0) {
System.out.println ("you have paid it all!! Thank you for coming;
}else {
System.out.println ("you have paid it back" + money + "you need to pay it back"+ super.getCeiling () );
}
}else {
System.out.println "Sorry, your account balance is insufficient or the amount of repayment entered is out of range! ");
}
}
Public void getloan() {// get the total amount of user loans
double savSum = 0;
};
}
package Account;
import java.util.Scanner;
import com_Day_7_11.SavingAccount;
//Storage clip class
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) {// loan method
If (0 < = money & & money < = 10000) {// the loan limit is 10000
System.out.println ("loan successful, your loan amount is" + money ");
System.out.println ("the amount you can still borrow is: + (10000 - money));
super.setCeiling (money); // pass the loan money to the loan attribute
super.setBalance ( super.getBalance () + money); // update balance value
System.out.println (your current balance is:+ super.getBalance ());
}else {
System.out.println "Sorry, your amount is not enough, the loan failed! ");
}
}
Public void payloan (double money) {// repayment
//Three criteria: 1. The repayment amount is less than or equal to the loan amount; 2. The repayment amount is less than the remaining amount; 3. The repayment amount is greater than 0
if (super.getBalance() >= money && money <= super.getCeiling() && money >= 0) {
super.setBalance ( super.getBalance () - money); // update balance
super.setCeiling(super.getCeiling() - money);
System.out.println "Your current balance is"+ super.getBalance ());
if (super.getCeiling() ==0) {
System.out.println ("you have paid it all!! Thank you for coming;
}else {
System.out.println ("you have paid it back" + money + "you need to pay it back"+ super.getCeiling () );
}
}else {
System.out.println "Sorry, your account balance is insufficient or the amount of repayment entered is out of range! ");
}
}
}
Main interface test function
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(); // call interface functions
int select = sc.nextInt();
switch(select) {
Case 1: b.openaccount(); // create an account
break;
Case 2: b.enter(); // log in
break;
default: System.out.println ("select business exception, please select again");
break;
}
System.out.println ("continue to select other business");
System.out.println (press 0 to exit);
System.out.println (please press 1 to continue to select other business);
select = sc.nextInt();
if (select == 0) {
break;
}
}
}
}
For more learning materials, please pay attention to the topic management system development.
The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.