永发信息网

C#编程习题

答案:1  悬赏:60  手机版
解决时间 2021-02-04 23:32
  • 提问者网友:箛茗
  • 2021-02-03 23:44
编写一个场景程序,一个人的类,有看网页,上QQ,玩游戏,电脑断电,随机循环产生方法,一直到出现电脑断电然后退出。
最佳答案
  • 五星知识达人网友:梦中风几里
  • 2021-02-03 23:55
public class People 
    {
        public People() { }
        public People(string _name) 
        {
            name = _name;
        }
        public string name = "";
        public void WatchWeb() 
        {
            Console.WriteLine("{0}在看网页", name);
        }
        public void QQ()
        {
            Console.WriteLine("{0}在上QQ", name);
        }
        public void PlayGame()
        {
            Console.WriteLine("{0}在玩游戏", name);
        }
        public void EndElectric()
        {
            Console.WriteLine("已断电...");
        }
        public void Execute(int random) 
        {
            switch (random)
            {
                case 1:
                    WatchWeb();
                    break;
                case 2:
                    QQ();
                    break;
                case 3:
                    PlayGame();
                    break;
                default: //4代表断电
                    EndElectric();
                    break;
            }
        }
    }
    class Program
    {
        public static void Main(string[] args)
        {
            People p = new People("张三");
            Random ran = new Random();
            int random = ran.Next(1, 5);
            p.Execute(random);
            while (random != 4 )
            {
                random = ran.Next(1, 5);
                p.Execute(random);
            } 
         }
    }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯