在 C# 中向银行账户添加利率

Posted

技术标签:

【中文标题】在 C# 中向银行账户添加利率【英文标题】:Adding Interest Rates to bank accounts in c# 【发布时间】:2021-09-21 07:10:41 【问题描述】:

我是 C# 新手,我为银行系统创建了三个帐户,它们是:Everyday、Investment 和 Omni。我遇到的问题是我无法弄清楚如何将利率和费用添加到班级账户中。以下是每个班级的要求:

日常账户:无利息、无透支、无费用

投资:所有资金的利率(不同),不允许透支,交易失败产生的费用。

Omni:仅对超过 1000 美元的余额支付的利率;指定允许透支;交易失败的费用。

将不胜感激将其添加到我的类和代码中的任何帮助。只是暂时卡住了。

// 日常账户

    class Everyday : Account
    
        //field

        private double minBalance;
        private double maxBalance;


        //properties
        public double MinBalance
         get  return this.minBalance;  

        public double MaxBalance
         get  return this.maxBalance;  

        //constructors

        public Everyday(double balance) : base()
        
            this.minBalance = 0;
            this.maxBalance = 1000000000000;
            this.balance = balance;
            accountType = "Everyday Account";
        

        //methods
    

// 投资账户

    class Investment : Account
    
        //field

        private double minBalance;
        private double maxBalance;


        //properties
        public double MinBalance
         get  return this.minBalance;  

        public double MaxBalance
         get  return this.maxBalance;  

        //constructors

        public Investment(double balance) : base()
        
            this.minBalance = 0;
            this.maxBalance = 1000000000000;
            this.balance = balance;
            accountType = "Investment Account";
        

        //methods
    

// 全方位账户

    class Omni : Account
    
        //field

        private double minBalance;
        private double maxBalance;


        //properties
        public double MinBalance
         get  return this.minBalance;  

        public double MaxBalance
         get  return this.maxBalance;  

        //constructors

        public Omni(double balance) : base()
        
            this.minBalance = 0;
            this.maxBalance = 1000000000000;
            this.balance = balance;
            accountType = "Omni Account";
        

        //methods
    

// 帐号

       class Account : Customer
       

        // Fields

        private double accountNumber;
        protected string accountType;

        protected double balance;
        protected double deposit;
        protected double withdrawal;

        // Properties

        public string AccountType
        
            get  return this.accountType; 
        

        public double Withdrawal
        
            get  return this.withdrawal; 
            set  this.withdrawal = value; 
        
        public double Deposit
        
            get  return this.deposit; 
            set  this.deposit = value; 
        
        public double AcctNumber
         get  return this.accountNumber;  

        public double Bal
         get  return this.balance;  


        // Creating Random Account Number

        public virtual double AccountNumb()
        
            Random rand = new Random();
            this.accountNumber = rand.Next(100000000, 1000000000);
            return accountNumber;
        


        //Computes General Balance(resets values)
        public virtual double Balance()
        
            balance = balance + deposit - withdrawal;
            deposit = 0;
            withdrawal = 0;
            return balance;
        

        //Computers Balance when withdrawal equals zero
        public virtual double DepositBalance(double input)
        
            deposit = input;
            withdrawal = 0;
            balance = balance + deposit - withdrawal;
            return balance;
        

        //Computers balance when deposit equals zero
        public virtual double WithBalance(double input)
        
            withdrawal = input;
            deposit = 0;
            balance = balance + deposit - withdrawal;
            return balance;
        


        //displays online banking menu
        public virtual void DisplayMenu()
        
            Console.WriteLine("Welcome to your online bank account\nPlease choose from the options below: ");
            Console.WriteLine("");
            Console.WriteLine("1.View Client Info");
            Console.WriteLine("");
            Console.WriteLine("2. View Account Balance:");
            Console.WriteLine("     2A.Everyday\n     2B.Investment\n     2C.Omni");
            Console.WriteLine("");
            Console.WriteLine("3.Deposit Funds:\n     3A.Everyday\n     3B.Investment\n     3C.Omni");
            Console.WriteLine("");
            Console.WriteLine("4.Withdraw Funds:\n     4A.Everyday\n     4B.Investment\n     4C.Omni");
            Console.WriteLine("");
            Console.WriteLine("5.Exit");
        


    

【问题讨论】:

也许可以为账户利率创建一个接口,您可以根据您需要的功能为每种类型的账户实现该接口。 不幸的是,我必须完全使用控制台来完成它,没有界面。 我不是说 UI,我是说这个 - Interfaces in C# 哦,好吧,不幸的是,我不确定如何处理利率问题 【参考方案1】:

投资类:` 投资类:账户 //字段

    private double minBalance;
    private double maxBalance;
    //add this
    private double tax;


    //properties
    public double MinBalance
     get  return this.minBalance;  

    public double MaxBalance
     get  return this.maxBalance;  
    public double Taxgetreturn this.tax;

    //constructors

    public Investment(double balance) : base()
    
        this.minBalance = 0;
        this.maxBalance = 1000000000000;
        this.balance = balance*Tax+balance;
        accountType = "Investment Account";
    

    //methods

and in omni class: Omni 类:帐户 //字段

    private double minBalance;
    private double maxBalance;
    private double Tax;


    //properties
    public double MinBalance
     get  return this.minBalance;  

    public double MaxBalance
     get  return this.maxBalance;  

    public double Taxgetreturn this.tax;
    //constructors

    public Omni(double balance) : base()
    
        this.minBalance = 0;
        this.maxBalance = 1000000000000;
        if (balance>=1000)this.balance=blance*Tax+balance
        else this.balance=balance
        accountType = "Omni Account";
    

    //methods

`

【讨论】:

请在您的回答中提供更多详细信息。正如目前所写的那样,很难理解您的解决方案。 在每个包含税的类中添加税属性,在构造函数中编辑余额以增加/减少税..这基于您的项目

以上是关于在 C# 中向银行账户添加利率的主要内容,如果未能解决你的问题,请参考以下文章

如何在 C# 中获取利率和银行同业拆借利率?

向银行系统添加利率和透支费

银行基本业务知识

如何在 C# 中向 powershellinstance 添加参数

在 C# 中向 JObject 添加匿名或对象属性

如何在 C# 中向窗口添加滚动条