日期:2014-05-18  浏览次数:20703 次

求高手编写一个汽车模块 并在窗体上实现
只用方法和属性!

要求 
1显示当前的时速,剩余电量,安全状态;

2在行驶中并踩下油门时;
(A)超过20时速且为佩戴安全带时,发出警告提示'为了您的行驶安全,请佩戴安全带'
(B)增加汽车的速度(+10)
(C)减少电量(—1)


------解决方案--------------------
C# code

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 语言来写的,写好了可以装入 控制器(单片机)

可能会涉及:
一些控制元件的驱动(比如测速元件,当前的电量测量模块,等等各传感器)
而且:
这些驱动程序,才是不好写的,要求程序员有相当的电路水平。
------解决方案--------------------
探讨
我认为这种程序:
一般是用C 语言来写的,写好了可以装入 控制器(单片机)

可能会涉及:
一些控制元件的驱动(比如测速元件,当前的电量测量模块,等等各传感器)
而且:
这些驱动程序,才是不好写的,要求程序员有相当的电路水平。