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

    }

}

  • 75
    点赞
  • 403
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
一个简单银行管理系统可以包括以下功能: 1. 用户注册和登录:用户可以通过注册创建账号,并且登录系统中。 2. 存款和取款:用户可以向自己的账户中存入现金,或者从账户中取出现金。 3. 查询余额:用户可以查询自己账户的余额。 4. 转账:用户可以向其他用户的账户中转账。 以下是一个简单Java实现: 首先,我们需要定义一个用户类,包括用户的姓名、账号、密码、余额等属性: ```java class User { private String name; private String account; private String password; private double balance; // 构造函数 public User(String name, String account, String password, double balance) { this.name = name; this.account = account; this.password = password; this.balance = balance; } // getter 和 setter 方法 public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAccount() { return account; } public void setAccount(String account) { this.account = account; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } } ``` 接着,我们定义一个银行类,用于管理用户的账户信息: ```java class Bank { private List<User> userList = new ArrayList<>(); // 添加用户 public void addUser(User user) { userList.add(user); } // 查询用户 public User getUser(String account, String password) { for (User user : userList) { if (user.getAccount().equals(account) && user.getPassword().equals(password)) { return user; } } return null; } // 存款 public boolean deposit(String account, double amount) { User user = getUser(account, password); if (user != null) { user.setBalance(user.getBalance() + amount); return true; } return false; } // 取款 public boolean withdraw(String account, double amount) { User user = getUser(account, password); if (user != null && user.getBalance() >= amount) { user.setBalance(user.getBalance() - amount); return true; } return false; } // 转账 public boolean transfer(String account1, String account2, double amount) { User user1 = getUser(account1, password); User user2 = getUser(account2, password); if (user1 != null && user2 != null && user1.getBalance() >= amount) { user1.setBalance(user1.getBalance() - amount); user2.setBalance(user2.getBalance() + amount); return true; } return false; } } ``` 最后,我们可以在主函数中实现用户的注册、登录、存款、取款、查询余额和转账等功能: ```java public static void main(String[] args) { Bank bank = new Bank(); // 注册用户 User user1 = new User("张三", "123456", "123456", 1000); User user2 = new User("李四", "654321", "654321", 2000); bank.addUser(user1); bank.addUser(user2); // 用户登录 User user = bank.getUser("123456", "123456"); if (user != null) { System.out.println("欢迎您," + user.getName() + "!"); } else { System.out.println("账号或密码错误!"); } // 存款 if (bank.deposit("123456", 500)) { System.out.println("存款成功,当前余额为:" + user.getBalance()); } else { System.out.println("账号或密码错误!"); } // 取款 if (bank.withdraw("123456", 200)) { System.out.println("取款成功,当前余额为:" + user.getBalance()); } else { System.out.println("账号或密码错误或余额不足!"); } // 查询余额 System.out.println("您的账户余额为:" + user.getBalance()); // 转账 if (bank.transfer("123456", "654321", 100)) { System.out.println("转账成功,当前余额为:" + user.getBalance()); } else { System.out.println("账号或密码错误或余额不足!"); } } ``` 以上就是一个简单银行管理系统Java实现。当然,实际的银行管理系统还需要更多的功能和安全措施,这里只是提供一个简单的示例。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值