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;
    }
}
相关推荐
InJre3 分钟前
QT widgets 窗口缩放,自适应窗口大小进行布局
开发语言·qt·ui
可愛小吉6 分钟前
Python 课程10-单元测试
开发语言·python·单元测试·tdd·unittest
五味香18 分钟前
C++学习,动态内存
java·c语言·开发语言·jvm·c++·学习·算法
无名之逆19 分钟前
计算机专业的就业方向
java·开发语言·c++·人工智能·git·考研·面试
爱棋笑谦25 分钟前
二叉树计算
java·开发语言·数据结构·算法·华为od·面试
翔云API1 小时前
人证合一接口:智能化身份认证的最佳选择
大数据·开发语言·node.js·ocr·php
jimmy.hua1 小时前
C++刷怪笼(5)内存管理
开发语言·数据结构·c++
xiaobai12 31 小时前
二叉树的遍历【C++】
开发语言·c++·算法
DieSnowK1 小时前
[项目][WebServer][Makefile & Shell]详细讲解
开发语言·c++·http·makefile·shell·项目·webserver
Freak嵌入式1 小时前
全网最适合入门的面向对象编程教程:50 Python函数方法与接口-接口和抽象基类
java·开发语言·数据结构·python·接口·抽象基类