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();
                }           
            }
        }
    }

    运行结果如下:

  • 相关阅读:
    Android Studio无法预览xml布局之解决方法(两种)
    ssm web.xml配置解析
    ssm框架下实现文件上传
    spring mvc使用@InitBinder 标签对表单数据绑定
    Jquery实现相对浏览器位置固定、悬浮
    asp,php,jsp 不缓存网页的办法
    Spring 2.5
    ERROR 1366 (HY000): Incorrect string value: 'xB3xA4xC9xB3' for column
    DELPHI SOKET 编程--使用TServerSocket和TClientSocket
    SVN switch 用法总结
  • 原文地址:https://www.cnblogs.com/syth/p/6137797.html
Copyright © 2011-2022 走看看