zoukankan      html  css  js  c++  java
  • C#方法定义和调用-2

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Qian
        {
            private decimal yuanlai;
            private string name;
            public Qian(string name)
            {
                this.yuanlai = 0;
                this.name = name;
                Print("我的钱数", 0);
            }
    
            public bool Desposit(decimal jine)
            {
                if (jine <= 0)
                    return false;
                yuanlai += jine;
                Print("借了别人",jine);
                return true;
            }
    
            public bool WithDraw(decimal jine)
            {
                if (jine > yuanlai || jine <= 0)
                    return false;
                yuanlai -= jine;
                Print("借给别人", jine);
                return true;
            }
    
            private void Print(string operation, decimal jine)
            {
                Console.WriteLine("我的名字:{0}",name);
                Console.WriteLine("{0}:{1}",operation,jine);
                Console.WriteLine("现在的钱:{0}",yuanlai);
                Console.WriteLine("============================");
                Console.ReadKey();
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                Qian q = new Qian("我是LT");
                bool succed = q.Desposit(10000);
                if (!succed)
                    Console.WriteLine("他不借给我钱!");
                succed = q.WithDraw(50000);
                if (!succed)
                    Console.WriteLine("我不借给他钱!");
                Console.ReadKey();
    
            }
        }
    }
  • 相关阅读:
    高精度模板_C++
    NOIP总结
    HDU2063_过山车_C++
    手写堆_C++
    NOIP2013Day1解题报告
    [ CodeVS冲杯之路 ] P1368
    POJ1002_487-3279_C++
    [ CodeVS冲杯之路 ] P1092
    POJ2376_Cleaning Shifts_C++
    欧几里得距离_曼哈顿距离_切比雪夫距离
  • 原文地址:https://www.cnblogs.com/blogofwyl/p/4307472.html
Copyright © 2011-2022 走看看