C#多种类的调用(模拟银行管理系统)(存在bug)

前言:

大家一起学习进步,提出改进意见

代码实现:

cs 复制代码
using System;
using System.Reflection;

namespace FIfthtest_banksystem
{
    public class Program
    {
        static void Main(string[] args)
        {
            Account[] accounts = new Account[3];
            {
                new Account { ClientAccount = "101", Name = "张麻子", ClientType = "vip", Password = "123", Money = 1000 };
                new Account { ClientAccount = "102", Name = "张帽子", ClientType = "normal", Password = "123", Money = 100 };
                new Account { ClientAccount = "103", Name = "张牧之", ClientType = "normal", Password = "123", Money = 10 };
            }
            bool flags = true;
            while (flags)
            {
                Console.WriteLine("请选择你的操作1.开户 2.销户 3.查找账户 4账户管理 5.退出");
                int choice = int.Parse(Console.ReadLine());
                Bank bank = new Bank();
                switch (choice)
                {
                    case 1:
                        bank.SetAccount();
                        break;
                    case 2:
                        bank.DeleteCilent(accounts);
                        break;
                    case 3:
                        bank.FindClient(accounts);
                        break;
                    case 4:
                        ATMPopAndPush atmPopAndPush = new ATMPopAndPush();
                        Console.WriteLine("请输入你的账号密码");
                        string acc= Console.ReadLine();
                        string pawd=Console.ReadLine();
                        atmPopAndPush.IsMatch(accounts, acc, pawd);
                        Console.WriteLine("请选择你的操作1.存钱 2.取钱 3.退出");
                        int choiceinner = int.Parse(Console.ReadLine());
                        Console.WriteLine("请输入屏幕提示的序号");
                        int index=int.Parse(Console.ReadLine());
                        switch (choiceinner)
                        {
                            case 1:
                                Console.WriteLine("请输入打算存入的金额");
                                float mon=int.Parse(Console.ReadLine());
                                atmPopAndPush.SaveMoney(accounts[index].Money,mon);
                                break;
                            case 2:
                                Console.WriteLine("请输入打算取出的金额");
                                float demon = int.Parse(Console.ReadLine());
                                atmPopAndPush.UpdateMoney(accounts[index].Money,demon);
                                break;
                            case 3:
                                flags = false;
                                break;
                            default:
                                Console.WriteLine("暂无此选项!");
                                break;
                        }
                        break;
                    case 5:
                        flags = false;
                        break;
                    default:
                        Console.WriteLine("暂无此选项!");
                        break;
                }
            }
        }
    }
}
//账号类
public class Account
{
    private string name;
    private string password;
    private float money;
    private string clientType;
    private string clientaccount;
    public string Name
    { get { return name; } set { name = value; } }
    public string Password
    { get { return password; } set { password = value; } }
    public float Money
    { get { return money; } set { money = value; } }
    public string ClientType
    { get { return clientType; } set { clientType = value; } }
    public string ClientAccount
    { get { return clientaccount; } set { clientaccount = value; } }


}
//银行类 开户,销户,查找账户
public class Bank
{
    public void SetAccount()
    {
        Console.WriteLine("Please input account,name,clienttype,password and money one by one!");
        string account = Console.ReadLine();
        string name = Console.ReadLine();
        string clientType = string.Empty;
        int password = int.Parse(Console.ReadLine());
        int money = int.Parse(Console.ReadLine());
        Console.WriteLine("choose index of normal or vip.");
        Console.WriteLine("11.normal    2.vip");
        int type = int.Parse(Console.ReadLine());
        switch (type)
        {
            case 1:
                clientType = "normal";
                Console.WriteLine("you choose noraml");
                break;
            case 2:
                clientType = "vip";
                Console.WriteLine("you choose noraml");
                break;
            default:
                Console.WriteLine("watch the request carefully!");
                break;
        }

    }
    public void FindClient(Account[] account)
    {
        Console.WriteLine("please input client's account");
        string sbaccount = Console.ReadLine();
            for (int i = 0; i <= account.Length; i++)
        {
            if (account[i].ClientAccount == sbaccount)
            { Console.WriteLine("Finded!"); }
            else { Console.WriteLine("NO ONE!"); }
        }
        
    }
    public void DeleteCilent(Account[] account)
    {
        Console.WriteLine("input the client's account you wanna delete!");
        int accountnum = int.Parse(Console.ReadLine());
        account[accountnum].ClientAccount = "已销户";
        account[accountnum].Name = "已销户";
        account[accountnum].ClientType = "已销户";
        account[accountnum].Money = 0;
        account[accountnum].Password = "已销户";
    }
}
//存款,取款,查账

public class ATMPopAndPush
{
    public bool IsMatch(Account[] account, string clientaccount, string password)
    {
        for (int i = 0; i < 3; i++)
        {
            if (account[i].ClientAccount == clientaccount && account[i].Password == password)
            {
                Console.WriteLine("你的序号是{0}", int.Parse(clientaccount)-1001);
                return true;
            }
            else
            {
                return false;
                Console.WriteLine("This card has banned.Please call us for helping!");
            }
        }
        return true;
    }
    public double SaveMoney(float money, float savedMoney)
    {
        Console.WriteLine("余额:{0}", money + savedMoney);
        return money + savedMoney;
    }
    public double UpdateMoney(float money, float delMoney)
    {
        Console.WriteLine("余额:{0}", money - delMoney);
        return money - delMoney;
    }
}
相关推荐
念九_ysl28 分钟前
Java 使用 OpenHTMLToPDF + Batik 将含 SVG 遮罩的 HTML 转为 PDF 的完整实践
java·开发语言·pdf
yaoxin52112337 分钟前
124. Java 泛型 - 有界类型参数
java·开发语言
liulilittle1 小时前
深度剖析:OPENPPP2 libtcpip 实现原理与架构设计
开发语言·网络·c++·tcp/ip·智能路由器·tcp·通信
88号技师1 小时前
2025年6月一区-田忌赛马优化算法Tianji’s horse racing optimization-附Matlab免费代码
开发语言·算法·matlab·优化算法
勤奋的知更鸟1 小时前
Java 编程之模板方法模式
java·开发语言·模板方法模式
上单带刀不带妹2 小时前
手写 Vue 中虚拟 DOM 到真实 DOM 的完整过程
开发语言·前端·javascript·vue.js·前端框架
-凌凌漆-3 小时前
【Qt】QStringLiteral 介绍
开发语言·qt
程序员爱钓鱼3 小时前
Go语言项目工程化 — 常见开发工具与 CI/CD 支持
开发语言·后端·golang·gin
军训猫猫头3 小时前
1.如何对多个控件进行高效的绑定 C#例子 WPF例子
开发语言·算法·c#·.net
真的想上岸啊4 小时前
学习C++、QT---18(C++ 记事本项目的stylesheet)
开发语言·c++·学习