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

  }

}

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

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

(0)

相关推荐

  • javaWeb实现学生信息管理系统

    本文为大家分享了javaWeb实现学生信息管理系统,供大家参考,具体内容如下 初始版 初始版是没有加分页的.因为没怎么学过前端,界面很丑陋.主要技术:JSP,JavaBean,servlet,JDBC主要页面如下: 登录页面 主页 添加学生 查看所有学生 查询学生 工程目录 数据库 两个表,user表和student表.为了使用DBUtils工具,一定要注意数据库表的属性的命名和JavaBean的get(),set() 方法的匹配.比如t_user表里的uname,在JavaBean中是:pri

  • java代码实现银行管理系统

    本文实例为大家分享了java银行管理系统的具体代码,供大家参考,具体内容如下 银行业务调度 一.系统要求 1.银行内有6个业务窗口,1 - 4号窗口为普通窗口,5号窗口为快速窗口,6号窗口为VIP窗口. 2.有三种对应类型的客户:VIP客户,普通客户,快速客户(办理如交水电费.电话费之类业务的客户). 3.异步随机生成各种类型的客户,生成各类型用户的概率比例为: VIP客户 :普通客户 :快速客户  =  1 :6 :3. 4.客户办理业务所需时间有最大值和最小值,在该范围内随机设定每个VIP客

  • Java+MySQL实现学生信息管理系统源码

    基于Java swing+MySQL实现学生信息管理系统:主要实现JDBC对学生信息进行增删改查,应付一般课设足矣,分享给大家.(由于篇幅原因,代码未全部列出,如有需要留下邮箱) 鉴于太多同学要源码,实在发不过来,上传到github上 https://github.com/ZhuangM/student.git 1. 开发环境:jdk7+MySQL5+win7 代码结构:model-dao-view 2. 数据库设计--建库建表语句: CREATE DATABASE student; DROP

  • 图书管理系统java代码实现

    本文实例为大家分享了java实现图书管理系统的具体代码,供大家参考,具体内容如下 /* (程序头部注释开始) * 程序的版权和版本声明部分 * Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved. * 文件名称:    <图书管理系统--java>                          * 作    者:       刘江波                       * 完成日期:    2012     年  3    

  • 一个简陋的java图书管理系统

    本文代码为原创一个简陋的管理系统,只做功能的测试.并没有去完善所有应有的功能,只做了输入输出查找,仅供参考! 菜单部分: import java.util.Scanner; public class Menu { int Min = 1; int Max = 3; public void getMenu(){ System.out.println("1.显示/2.输入/3.查找"); } public void getFindMenu(){ System.out.println(&qu

  • Java+Mysql学生管理系统源码

    最近正在学java和数据库,想起以前写的学生管理系统,都是从网上下载,敷衍了事.闲来无事,也就自己写了一个,不过功能实现的不是很多. 开发语言:java: 开发环境:Mysql, java: 开发工具:eclipse 开发此案例,首先得在电脑上有java开发环境和Mysql, java开发环境与Mysql的搭建,就不再叙述了,如果需要,请联系我最下面的联系方式:dingyelf@aliyun.com 此次系统比较简易:数据库中只有一个表:stu;功能:能够对学生增加.删除.修改. 开发步骤:  

  • java实现银行管理系统

    本文实例为大家分享了java实现银行管理系统的具体代码,供大家参考,具体内容如下 Bank类 package First; import java.util.TreeSet; //银行类 public class Bank { private String Bankname = "坑对对银行"; //银行名称 TreeSet<User> holder = null; //银行存储的信息 private static Bank INSTANCE = new Bank(); p

  • java学生信息管理系统源代码

    本文实例为大家分享了java学生信息管理系统的具体代码,实现学生信息: 增加 int[] a=new int[9] .删除 .查找.更改,供大家参考,具体内容如下 /*学生信息管理系统,实现学生信息: *增加 int[] a=new int[9] *删除 *查找 *更改 */ import java.util.Scanner;//导入java输入流 import java.lang.*; import java.io.*; class Student { private static Stude

  • 图书管理系统java版

    本文的目的就是通过图书管理系统掌握数据库编程技术,能正确连接数据库,能对数据库中信息进行查询.插入.删除.修改. 内容:在数据库中创建一张书目信息表,包括书名.作者.出版社.出版日期.书号.价格字段.设计一个GUI界面进行书目管理.在该界面上有四个选项卡,分别是查询.插入.删除.修改.点击查询选项卡,出现的界面上有书名.作者.出版社.书号四个文本框,一个按钮和一个只读文本区.文本框内容可以为空,输入相应的查询信息后(例如根据书名查询可以仅输入书名),点击界面上的"查询"按钮,可以在界面

  • java学生管理系统界面简单实现(全)

    学生管理系统简单的实现,供初学Java Swing同学学习使用. import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import jav

随机推荐