日期:2014-05-18 浏览次数:20924 次
public class car
{
  public bool SafeBelt
   {
     get;
     set;
   }
  public int Speed
   { 
     get;
     set;
   }
  public int Power
   {
    get;
    set;
   }
   public car(int speed,int power)
    {
      this.Speed=speed;
      this.Power=power;
    }
  public ShowNow()//显示当前状态
   {
   return this.Speed,this.Power;
   }
  public GetSafe()
   {
    //安全状态
   }
   public Warn()
   {
   if(this.Speed>=20&&/*未系安全带*/)
      {
       MessageBox.Show("为了您的行驶安全,请佩戴安全带");
     }
   }
}
------解决方案--------------------
public class car
{
 // 是否佩戴了安全帽
 public bool SafeBelt
  {
    get;
    set;
  }
 // 当前的速度
 public int Speed
  {  
    get;
  }
 // 当前的电量
 public int Power
  {
   get;
  }
  public car(int speed,int power)
   {
     this.Speed=speed;
     this.Power=power;
   }
  // 踩油门加速
  public SpeedUp()
  {
    if(this.Speed + 10 >=20 && !SafeBelt)
     {
      MessageBox.Show("为了您的行驶安全,请佩戴安全带");
      return;
    }
    if(this.Power - 1 = 0)
     {
      MessageBox.Show("电量不足");
      return;
    }
    this.Speed = this.Speed + 10;
    this.Power= this.Power - 1;
  }
}
------解决方案--------------------
先分析,再动手,就不会改了,写了,又要改。
------解决方案--------------------
我认为这种程序:
 一般是用C 语言来写的,写好了可以装入 控制器(单片机)
可能会涉及:
 一些控制元件的驱动(比如测速元件,当前的电量测量模块,等等各传感器)
而且:
 这些驱动程序,才是不好写的,要求程序员有相当的电路水平。
------解决方案--------------------