使用储蓄和帐户类的C#程序,并且必须有储蓄类的构造函数

时间:2019-06-11 12:03:20

标签: c#

Deposite()会将金额与余额相加。 Withdraw()将从余额中扣除金额。 GetBalance()将退还余额。 GetInterest()将通过计算余额*(interest / 100)

来返回利息金额。
class BankAccount 
{ 
public string accountName; 
public int accountBalance; 
public int accountNumber; 
public BankAccount(string name, int number) 
{ 
    accountName = name; 
    accountNumber = number; 
} 
public int getAccountNumber() 
{ 
    return accountNumber; 
} 
public void setAccountNumber(int newNumber) 
{ 
    accountNumber = newNumber; 
} 
}

1 个答案:

答案 0 :(得分:0)

我认为您需要这个......

class BankAccount
    {
        public string accountName;
        public int accountBalance;
        public int accountNumber;


        public BankAccount(string name, int number)
        {
            accountName = name;
            accountNumber = number;
        }

        public int getAccountNumber()
        {
            return accountNumber;
        }

        public void setAccountNumber(int newNumber)
        {
            accountNumber = newNumber;
        }

        public void Deposite(int dep)
        {
            this.accountBalance = accountBalance + dep;
        }

        public void Withdraw(int dep)
        {
            this.accountBalance = accountBalance - dep;
        }

        public int GetBalance()
        {
            return this.accountBalance;
        }


        public double GetInterest(int interest)
        {
            double val = this.accountBalance * (interest / 100);

            return val;
        }

    }