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

news/2025/2/22 0:05:10/

前言:

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

代码实现:

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


http://www.ppmy.cn/news/1244850.html

相关文章

P23 C++字符串

目录 前言 01 什么是字符串 02 字符串是怎么工作的呢&#xff1f; 2.1 字符 2.2 字符串 2.3 如何知道指向hello world的这个指针多大 03 使用字符串 04 字符串传参 前言 本期我们将讨论 C 中的字符串。 首先&#xff0c;什么是字符串&#xff1f; 01 什么是字符串 字…

第二题-差值-【第六届传智杯程序设计挑战赛解题分析详解复盘】(JavaPythonC++实现)

🚀 欢迎来到 ACM 算法题库专栏 🚀 在ACM算法题库专栏,热情推崇算法之美,精心整理了各类比赛题目的详细解法,包括但不限于ICPC、CCPC、蓝桥杯、LeetCode周赛、传智杯等等。无论您是刚刚踏入算法领域,还是经验丰富的竞赛选手,这里都是提升技能和知识的理想之地。 ✨ 经典…

Spring Boot 3.2 新特性之 JdbcClient

SpringBoot 3.2引入了新的 JdbcClient 用户数据库操作&#xff0c;JdbcClient对JdbcTemplate进行了封装&#xff0c;采用了 fluent API 的风格&#xff0c;可以进行链式调用。 自此&#xff0c;spring自带的数据库操作有了4种方式&#xff1a;JdbcTemplate、JdbcClient、Sprin…

CMAKE的学问

cmake&#xff1a;指定install的安装目录 在执行 cmake 命令时指定 cmake -DCMAKE_INSTALL_PREFIX<你想要安装的路径>在CMakeLists.txt设置 CMAKE_INSTALL_PREFIX 变量 SET(CMAKE_INSTALL_PREFIX <install_path>) INSTALL(TARGETS test DESTINATION bin)要加在PR…

python:使用for循环与while循环打印九九乘法表

python&#xff1a;使用for循环与while循环打印九九乘法表 在编程中&#xff0c;for循环和while循环是两种常用的循环结构&#xff0c;它们可以用来实现各种不同的功能和逻辑。其中&#xff0c;九九乘法表是一个经典的例子&#xff0c;可以用来展示for循环和while循环的使用方…

数据资产入表在即,企业要从数据治理入手

数据是驱动数字经济发展的核心生产要素&#xff0c;数据资产化是释放数据要素价值的重要方式。2024年1月1日&#xff0c;《企业数据资源相关会计处理暂行规定》将正式实施。企业数据资产入表已进入倒计时&#xff0c;企业作如何充分发挥海量规模数据和应用场景等优势&#xff0…

qInstallMessageHandler的学习

背景&#xff1a;需要做一个日志系统。 把信息重定向到txt文件中。 参考&#xff1a; QT 调试信息如何输出到文件&#xff08;qDebug/qWarning/qCritical/qFatal&#xff09;-CSDN博客 Qt 之 qInstallMessageHandler&#xff08;重定向至文件&#xff09;-CSDN博客 demo…

Gitee上传代码教程

1. 本地安装git 官网下载太慢&#xff0c;我们也可以使用淘宝镜像下载&#xff1a;CNPM Binaries Mirror 安装成功以后电脑会有Git Bush标识&#xff0c;空白处右键也可查看。 2. 注册gitee账号&#xff08;略&#xff09; 3. 创建远程仓库 4. 上传代码 4.1 在项目文件目录…