java实现简单银行管理系统

论坛 期权论坛 脚本     
niminba   2021-5-23 02:59   1101   0

本文实例为大家分享了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,count(){}
  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;
      }
    }
 
  }
 
}

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

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

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1060120
帖子:212021
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP