热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

java实现简单银行管理系统

这篇文章主要为大家详细介绍了java实现简单银行管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了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 

信用卡类

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;
      }
    }
 
  }
 
}

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

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


推荐阅读
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • Java太阳系小游戏分析和源码详解
    本文介绍了一个基于Java的太阳系小游戏的分析和源码详解。通过对面向对象的知识的学习和实践,作者实现了太阳系各行星绕太阳转的效果。文章详细介绍了游戏的设计思路和源码结构,包括工具类、常量、图片加载、面板等。通过这个小游戏的制作,读者可以巩固和应用所学的知识,如类的继承、方法的重载与重写、多态和封装等。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 本文介绍了如何在给定的有序字符序列中插入新字符,并保持序列的有序性。通过示例代码演示了插入过程,以及插入后的字符序列。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 本文介绍了Java高并发程序设计中线程安全的概念与synchronized关键字的使用。通过一个计数器的例子,演示了多线程同时对变量进行累加操作时可能出现的问题。最终值会小于预期的原因是因为两个线程同时对变量进行写入时,其中一个线程的结果会覆盖另一个线程的结果。为了解决这个问题,可以使用synchronized关键字来保证线程安全。 ... [详细]
  • 本文详细介绍了Java中vector的使用方法和相关知识,包括vector类的功能、构造方法和使用注意事项。通过使用vector类,可以方便地实现动态数组的功能,并且可以随意插入不同类型的对象,进行查找、插入和删除操作。这篇文章对于需要频繁进行查找、插入和删除操作的情况下,使用vector类是一个很好的选择。 ... [详细]
  • 猜字母游戏
    猜字母游戏猜字母游戏——设计数据结构猜字母游戏——设计程序结构猜字母游戏——实现字母生成方法猜字母游戏——实现字母检测方法猜字母游戏——实现主方法1猜字母游戏——设计数据结构1.1 ... [详细]
  • Android源码深入理解JNI技术的概述和应用
    本文介绍了Android源码中的JNI技术,包括概述和应用。JNI是Java Native Interface的缩写,是一种技术,可以实现Java程序调用Native语言写的函数,以及Native程序调用Java层的函数。在Android平台上,JNI充当了连接Java世界和Native世界的桥梁。本文通过分析Android源码中的相关文件和位置,深入探讨了JNI技术在Android开发中的重要性和应用场景。 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • 本文介绍了Android 7的学习笔记总结,包括最新的移动架构视频、大厂安卓面试真题和项目实战源码讲义。同时还分享了开源的完整内容,并提醒读者在使用FileProvider适配时要注意不同模块的AndroidManfiest.xml中配置的xml文件名必须不同,否则会出现问题。 ... [详细]
  • Android开发实现的计时器功能示例
    本文分享了Android开发实现的计时器功能示例,包括效果图、布局和按钮的使用。通过使用Chronometer控件,可以实现计时器功能。该示例适用于Android平台,供开发者参考。 ... [详细]
author-avatar
ygluo
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有