zoukankan      html  css  js  c++  java
  • 《实时控制软件设计》第二周作业

    停车场门禁系统状态机:

                                                      

    代码如下:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace qichemenjin
    {
        /// <summary>
        /// 判断起降杆状态
        /// </summary>
        class LiftLever
        {
            public bool llstate;
            public LiftLever()
            {
                llstate = false;
            }
           
            
            public void Showllstate()
            {
                if (llstate == true)
                    Console.WriteLine("起落杆升");
                else
                    Console.WriteLine("起落杆降");
            }
        }
        /// <summary>
        /// 判断等的状态
        /// </summary>
        class TrafficLight
        {
            public bool tlstate;
            public TrafficLight()
            {
                tlstate = false;
            }
           
            
            public void Showtlstate()
            {
                if (tlstate == true)
                    Console.WriteLine("绿灯亮");
                else
                    Console.WriteLine("红灯亮");
            }
        }
        /// <summary>
        /// 判断车的状态
        /// </summary>
        class Car
        {
            public bool carstate;
            public Car()
            {
                carstate = false;
            }
            public void Showcarstate()
            {
                if (carstate == true)
                    Console.WriteLine("有车入闸");
                else
                    Console.WriteLine("车已出闸");
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                Car car = new Car();
                LiftLever lever = new LiftLever();
                TrafficLight light = new TrafficLight();
                car.Showcarstate();
                lever.Showllstate();
                light.Showtlstate();            
                while (car.carstate=true)
                {
                    Console.WriteLine("是否有车入闸(y/n)");
                    var input = Console.Read();
                    if(input=='y')
                    {
                        car.carstate = true;
                        car.Showcarstate();
                        lever.llstate = true;
                        lever.Showllstate();
                        light.tlstate = true;
                        light.Showtlstate();
                        Console.Read();
                    }
                    else
                    {
                        Console.WriteLine("车已出闸");
                        Console.WriteLine("起落杆降");
                        Console.WriteLine("红灯亮");
                        
                        Console.Read();
                    }
                    Console.Read();
                }           
            }
        }
    }

    运行结果如下:

  • 相关阅读:
    学习Tomcat(三)
    TIME_WAIT 优化注意事项
    TIME_WAIT 优化
    TCP(一)
    TCP(二)
    TCP(三)
    5-14 练习题及答案
    5-14 进程池
    5-11 操作系统介绍
    5-8套接字socket
  • 原文地址:https://www.cnblogs.com/syth/p/6137797.html
Copyright © 2011-2022 走看看