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

前言:

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

代码实现:

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

你可能感兴趣的:(c#,bug,开发语言)