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;
    }
}
相关推荐
妮妮喔妮34 分钟前
【无标题】
开发语言·前端·javascript
fie888939 分钟前
浅谈几种js设计模式
开发语言·javascript·设计模式
喝可乐的布偶猫1 小时前
Java类变量(静态变量)
java·开发语言·jvm
喝可乐的布偶猫1 小时前
韩顺平之第九章综合练习-----------房屋出租管理系统
java·开发语言·ide·eclipse
江山如画,佳人北望2 小时前
C#程序入门
开发语言·windows·c#
与火星的孩子对话2 小时前
Unity进阶课程【六】Android、ios、Pad 终端设备打包局域网IP调试、USB调试、性能检测、控制台打印日志等、C#
android·unity·ios·c#·ip
future14123 小时前
C#每日学习日记
java·学习·c#
coding随想3 小时前
JavaScript中的BOM:Window对象全解析
开发语言·javascript·ecmascript
念九_ysl3 小时前
Java 使用 OpenHTMLToPDF + Batik 将含 SVG 遮罩的 HTML 转为 PDF 的完整实践
java·开发语言·pdf
yaoxin5211233 小时前
124. Java 泛型 - 有界类型参数
java·开发语言