欢迎来到天天文库
浏览记录
ID:17558072
大小:30.00 KB
页数:6页
时间:2018-09-03
《银行存取款案例(c#编程)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、银行存取款案例(C#编程)classSavingsAccount{//类字段用于存储帐号、余额和已获利息privateint_accountNumber;privatedouble_balance;privatedouble_interestEarned;//利率是静态的,因为所有帐户获得的利息相同privatestaticdouble_interestRate;//构造函数初始化类成员publicSavingsAccount(intaccountNumber,doublebalance){this._accountNumber=accountN
2、umber;this._balance=balance;}//只读AccountNumber属性publicintAccountNumber{get{return_accountNumber;}}publicdoubleInterestEarned{get{return_interestEarned;}set{//验证数据if(value<0.0){Console.WriteLine("利息不能为负数");return;}_interestEarned=value;}}publicstaticdoubleInterestRate{get{retu
3、rn_interestRate;}set{//验证数据if(value<0.0){Console.WriteLine("利率不能为负数");return;}else{_interestRate=value/100;}}}publicdoubleBalance{get{if(_balance<0)Console.WriteLine("没有可用余额");return_balance;}set{_balance=value;}}voidputmoney(doublemoney){Console.WriteLine("您原来的存款余额为:{0}",_ba
4、lance);_balance+=money;Console.WriteLine("您现在的存款余额为:{0}",_balance);}voidgetmoney(doublemoney){Console.WriteLine("您原来的存款余额为:{0}",_balance);_balance-=money;Console.WriteLine("您现在的存款余额为:{0}",_balance);}voidshowbalance(){Console.WriteLine("您现在的存款余额为:{0}",_balance);}staticvoidMain
5、(string[]args){//创建SavingsAccount的对象SavingsAccountobjSavingsAccount=newSavingsAccount(12345,5000);intchoice;do{Console.WriteLine("请选择功能选项:");Console.WriteLine("1、计算利息");Console.WriteLine("2、存钱");Console.WriteLine("3、取钱");Console.WriteLine("4、显示余额");Console.WriteLine("5、退出");c
6、hoice=Convert.ToInt32(Console.ReadLine());switch(choice){case1:{Console.WriteLine("输入到现在为止已获得的利息");objSavingsAccount.InterestEarned=Int64.Parse(Console.ReadLine());Console.WriteLine("输入到现在为止已获得的利率");SavingsAccount.InterestRate=Int64.Parse(Console.ReadLine());objSavingsAccount
7、.InterestEarned+=objSavingsAccount.Balance*SavingsAccount.InterestRate;Console.WriteLine("获得的总利息为:{0}",objSavingsAccount.InterestEarned);Console.WriteLine("输入到现在为止已获得的利率");break;}case2:{Console.WriteLine("输入存入的金额");doublemoney=Double.Parse(Console.ReadLine());objSavingsAccoun
8、t.putmoney(money);break;}case3:{Console.WriteLine("输入要取出的金额");double
此文档下载收益归作者所有