using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace 面相对象聊天机器人
{
    class Program
    {
        static void Main(string[] args)
        {
            机器人 r1 = new 机器人();
            r1.Name = "Mother Fucker";
            r1.Eat(10);
            r1.SayHello();
            while (true)
            {
                string str = Console.ReadLine();
                r1.Speak(str);
            }
        }
    }
    class 机器人
    { 
        public string Name{get;set;}
        private int FullLevel{get;set;} 
        public void SayHello()
        {
            Console.WriteLine("大家好我叫{0}",Name);
        }
        public void Eat(int FoodCount)
        {
            if (FullLevel >= 100)
                return;
            FullLevel = FullLevel + FoodCount;
        }
        public string Speak(string str)
        {
            if (FullLevel <= 0)
            {
                Console.WriteLine("饿死了,不说了");
                return;
            }
            if (str.Contains("姓名")||str.Contains("名字"))
            {
                this.SayHello();//类的内部调用自己的方法
            }
            else if (str.Contains("女朋友"))
            {
                Console.WriteLine("年龄小,不考虑");
            }
            else
            {
                Console.WriteLine("听不懂!");
            }
            FullLevel--;
        }
   
    }
}

解决方案 »

  1.   


    using System;namespace 面相对象聊天机器人
    {
        class Program
        {
            static void Main(string[] args)
            {
                机器人 r1 = new 机器人();
                r1.Name = "Mother Fucker";
                r1.Eat(10);
                r1.SayHello();
                while (true)
                {
                    string str = Console.ReadLine();
                    r1.Speak(str);
                }
            }
        }
        class 机器人
        {
            public string Name { get; set; }
            private int FullLevel { get; set; }
            public void SayHello()
            {
                Console.WriteLine("大家好我叫{0}", Name);
            }
            public void Eat(int FoodCount)
            {
                if (FullLevel >= 100)
                    return;
                FullLevel = FullLevel + FoodCount;
            }
            public void Speak(string str)//Speak的返回值是void
            {
                if (FullLevel <= 0)
                {
                    Console.WriteLine("饿死了,不说了");
                    return;
                }
                if (str.Contains("姓名") || str.Contains("名字"))
                {
                    this.SayHello();
                }
                else if (str.Contains("女朋友"))
                {
                    Console.WriteLine("年龄小,不考虑");
                }
                else
                {
                    Console.WriteLine("听不懂!");
                }
                FullLevel--;
            }
        }
    }
      

  2.   

    命名规则,最好不要用中文 另外就如同2楼所说的,SPeaker方法的返回值是Void
      

  3.   

    说呢么烂代码?!如果我问“有个傻X它的姓名是什么来着?”,机器人此时也SayHello吗?