연습1: MyBank 시스템의 인출 기능을 실현teacher

3462 단어
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyBank
{
    public class Bank
    {
        User user = new User();  // User 

        /// 
        ///  
        /// 
        public void CreateAccount()
        {
            // 
            user._name = " ";
            user._account = "179708064356";
            user._password = "1234";
            user._identityNum = "2100506198908081847";
            user._balance = 8000;

            Console.WriteLine(" :{0}, :{1}, :{2} !", user._account, user._name, user._balance);
            Console.WriteLine();
        }

        #region  
        /// 
        ///  
        /// 
        public void WithDraw()
        {
            string account = "";             // 
            string pwd;                      // 

            Console.WriteLine(" :");
            account = Console.ReadLine();
            if (account.Length == 0)
            {
                Console.WriteLine(" !");
                return;
            }

            // , 
            Console.WriteLine(" :");
            pwd = Console.ReadLine();

            if (user._password != pwd)
            {
                Console.WriteLine(" !");
                return;
            }

            Console.WriteLine(" ");
            double money = double.Parse(Console.ReadLine());
            double result = user.MinusMoney(money);
            if (result == -1)// 
            {
                Console.WriteLine(" ");
            }
            else
            {
                Console.WriteLine(" ! :" + result);
            }
        }
        #endregion
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyBank
{
    /// 
    ///  
    /// 
    public class User
    {
        /// 
        ///  
        /// 
        public string _name;

        /// 
        ///  
        /// 
        public string _password;

        /// 
        ///  
        /// 
        public string _identityNum;

        /// 
        ///  
        /// 
        public double _balance;

        /// 
        ///  
        /// 
        public string _account;


        /// 
        ///  
        /// 
        ///  
        ///  , -1
        public double MinusMoney(double money)
        {
            if (money > 0)
            {
                if (money <= _balance)
                {
                    _balance -= money;
                    return _balance;
                }
                else
                {
                    return -1;
                }

            }
            else
            {
                return -1;
            }
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyBank
{
    class Program
    {
        static void Main(string[] args)
        {   
            Bank myBank = new Bank();
            // 
            myBank.CreateAccount();
            // 
            myBank.WithDraw();
            
            Console.ReadLine();
        }
    }
}

좋은 웹페이지 즐겨찾기