java 银行管理系统

import java.util.Scanner;

public class Util
{   boolean isFlag=true;
    boolean flag=false;
    Scanner scan=new Scanner(System.in);
    Atm a=new Atm();
    public void adminpass()
    {
        System.out.println("请输入管理员密码:");
        int adminpassword=scan.nextInt();
        if(adminpassword==1)
        {
            flag=true;
        }
    }
    public void mainSystem()
    {

        while(isFlag&&flag)
        {
            System.out.println("1.开户");
            System.out.println("2.查询");
            System.out.println("3.存款");
            System.out.println("4.取款");
            System.out.println("5.转账");
            System.out.println("6.改密码");
            System.out.println("7.锁定");
            System.out.println("8.解锁");
            System.out.println("9.补卡");
            System.out.println("10.销户");
            System.out.println("退出(0)");
            System.out.println("请输入需要的操作:");
            int count=scan.nextInt();
            switch (count)
        {
            case 1:
                a.newCard();
                break;
            case 2:
                a.search();
                break;
            case 3:
                a.putOut();
                break;
            case 4:
                a.putin();
                break;
            case 5:
                a.transfer();
                break;
            case 6:
                a.changePassword();
                break;
            case 7:
                a.lockDown();
                break;
            case 8:
                a.unlockDown();
                break;
            case 9:
                a.cardReplacement();
                break;
            case 10:
                a.logOff();
                break;
            case 0:
                isFlag=false;
            break;
        }
        }
    }
}

package org.example;

import java.util.Scanner;

public class Atm {
    int userCount = 0;
    User u[] = new User[100];
    Card c[] = new Card[100];
    Scanner scan = new Scanner(System.in);
    boolean flag=true;

    private boolean isExiste(int id) {
        boolean flag = true;
        for (int i = 0; i < userCount; i++) {
            if (c[i].cardId == id) {
                flag = true;
                break;
            } else {
                flag = false;
                break;
            }
        }
        return flag;
    }

    private boolean checkBalance(double putOut, int id) {
        int index = getIndex(id);
        if (c[index].balance - putOut > 0) {
            return true;
        } else {
            return false;
        }
    }

    private int getIndex(int id) {
        int index = 0;
        for (int i = 0; i < userCount; i++) {
            if (c[i].cardId == id) {
                index = i;
            }


        }
        return index;
    }

    private boolean checkCard(String password, int index) {
        if (password.equals(c[index].password)) {
            return true;
        } else {
            return false;
        }
    }

    public void newCard() {


        userCount++;

        c[userCount - 1] = new Card();
        u[userCount - 1] = new User();
        System.out.println("姓名:");
        u[userCount - 1].name = scan.next();
        System.out.println("身份证:");
        u[userCount - 1].userId = scan.next();
        System.out.println("手机号:");
        u[userCount - 1].phone = scan.next();
        c[userCount - 1].cardId = (int) (Math.random() * 1000);
        System.out.println("预存金额:");
        double newBalance = scan.nextDouble();
        c[userCount - 1].balance += newBalance;
        System.out.println("密码:");
        c[userCount - 1].password = scan.next();
        System.out.println("卡号:" + c[userCount - 1].cardId);
    }

    public void search() {
        System.out.println("输入卡号");
        int temp = scan.nextInt();
        System.out.println("输入密码");
       // int index=getIndex()
        String temp2 = scan.next();
        for (int i = 0; i < userCount; i++) {
            if (c[i].cardId == temp) {
                if(c[i].isflag)
                {
                    if (checkCard(temp2, i)) {
                        System.out.println("余额:" + c[i].balance);
                        break;
                    } else {
                        System.out.println("密码错误");
                        break;
                    }

                }
                else
                {
                    System.out.println("已锁定,请解锁");
                }
            }
            if (i == userCount - 1) {
                System.out.println("查无此卡");
            }


        }
    }

    public void putin() {
        System.out.println("请输入卡号:");
        int temp1 = scan.nextInt();
        System.out.println("输入密码");
        String temp2 = scan.next();
        System.out.println("请输入存款金额");
        double putIn = scan.nextDouble();
        int index = getIndex(temp1);
        if (isExiste(temp1)) {
            if(c[index].isflag)
            {
                if (checkCard(temp2, index)) {
                    c[index].balance += putIn;
                    System.out.println("存款成功");
                } else {
                    System.out.println("密码错误");
                }
            }
            else
            {
                System.out.println("已锁定,请解锁");
            }
        } else {
            System.out.println("查无此卡");
        }
    }

    public void putOut() {
        System.out.println("请输入取款卡号");
        int id = scan.nextInt();
        if (isExiste(id)) {
            System.out.println("请输入密码");
            String password = scan.next();
            int index = getIndex(id);
            if(c[index].isflag)
            {
                if (checkCard(password, index)) {
                    System.out.println("请输入取款金额");
                    double putOut = scan.nextDouble();
                    if (checkBalance(putOut, id)) {
                        c[index].balance -= putOut;
                        System.out.println("取款成功");
                    } else {
                        System.out.println("余额不足");
                    }
                }
            }
            else
            {
                System.out.println("已锁定,请解锁");
            }
        } else {
            System.out.println("查无此卡");
        }


    }

    public void transfer() {
        System.out.println("请输入转出卡号");
        int id1 = scan.nextInt();
        if (!isExiste(id1)) {
            System.out.println("查无此卡");
        }
        System.out.println("请输入转入卡号");
        int id2 = scan.nextInt();
        if (!isExiste(id2)) {
            System.out.println("查无此卡");
        }
        System.out.println("转出卡密码");
        String password = scan.next();
        int index1 = getIndex(id1);
        int index2 = getIndex(id2);
        if(c[index1].isflag)
        {
            if(c[index2].isflag)
            {
                if (checkCard(password, index1)) {
                    System.out.println("请输入转账金额");
                    double transfer = scan.nextDouble();
                    if (checkBalance(transfer, id2)) {
                        c[index1].balance -= transfer;
                        c[index2].balance += transfer;
                    } else {
                        System.out.println("余额不足");
                    }
                } else {
                    System.out.println("密码错误");
                }
            }
            else
            {
                System.out.println("转入卡已锁定");
            }
        }
        else
        {
            System.out.println("转出卡已锁定");
        }
    }

    public void changePassword() {
        System.out.println("输入账号");
        int id = scan.nextInt();
        if (isExiste(id)) {
            System.out.println("输入密码");
            String password = scan.next();
            int index = getIndex(id);
            if(c[index].isflag)
            {
                if (checkCard(password, index)) {
                    System.out.println("请输入修改的密码");
                    String password2 = scan.next();
                    if (password.equals(password2)) {
                        System.out.println("错误,两次密码一致");
                    } else {
                        c[index].password = password2;
                        System.out.println("修改成功");
                    }
                } else {
                    System.out.println("密码错误");
                }
            }
            else
            {
                System.out.println("已锁定,请解锁");
            }
        } else {
            System.out.println("查无此卡");
        }
    }

    public void cardReplacement() {
        System.out.println("请输入补卡的卡号");
        int cardId = scan.nextInt();

        if (isExiste(cardId)) {
            int index = getIndex(cardId);
            System.out.println("输入您的身份证号码:");
            String userId = scan.next();
            if (userId.equals(u[index].userId)) {
                System.out.println("请输入新的密码");
                String password = scan.next();
                c[index].password = password;
                System.out.println("补卡成功!");
            } else {
                System.out.println("身份异常");
            }
        } else {
            System.out.println("查无此卡");
        }
    }

    public void lockDown()
    {
        System.out.println("输入银行卡号");
        int id=scan.nextInt();
        if(isExiste(id))
        {
            int index=getIndex(id);
            System.out.println("请输入密码");
            String password=scan.next();
            if(checkCard(password,index))
            {
                c[index].isflag=false;
                //flag=false;
                System.out.println("成功锁定");
            }
            else
            {
                System.out.println("密码错误");
            }
        }
        else
        {
            System.out.println("查无此卡");
        }
    }
    public void unlockDown()
    {
        System.out.println("输入银行卡号");
        int id=scan.nextInt();
        if(isExiste(id))
        {
            int index=getIndex(id);
            System.out.println("输入密码");
            String password=scan.next();
            if(checkCard(password,index))
            {
                c[index].isflag=true;
                //flag=true;
                System.out.println("解锁成功");
            }
            else
            {
                System.out.println("密码错误");
            }
        }
        else
        {
            System.out.println("查无此卡");
        }
    }
    public void logOff()
    {
        System.out.println("输入银行卡号");
        int id=scan.nextInt();
        if(isExiste(id))
        {
            int index=getIndex(id);
            System.out.println("输入密码");
            String password=scan.next();
            if(checkCard(password,index))
            {
                System.out.println("注销成功");
                c[index].cardId=0;
            }
            else
            {
                System.out.println("密码错误");
            }
        }
        else
        {
            System.out.println("查无此卡");
        }
    }

}

package org.example;

public class Card
{
    int cardId;
    String password;
    double balance=0;
    boolean isflag=true;

}

package org.example;

public class Admin
{
    public static void main(String[] args) {

        Util tool=new Util();
        tool.adminpass();
       tool.mainSystem();

    }
}

package org.example;

public class User
{
    String name;
    String userId;
    String phone;
    //int  usersCount=0;

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值