问题 编写机动车类Vehicle,包含以下成员:
(1)常量:最高速度;
(2)字段:车牌号,车辆颜色,行驶速度;
(3)构造函数:初始化车段值;
(3)属性:车牌号;车辆颜色,行驶速度;
(4)方法:车辆加速方法,返回加速后的行驶速度,加速过程中车辆行驶速度不能超过最高速度;
(5)方法:车辆减速方法,返回减速后的行驶速度,减速过程中车辆行驶速度不能小于0;
(6) 方法:输出车辆基本信息及当前速度。
建立一个Program类的Main()方法,创建一个机动车对象,输出加减速前的车辆基本信息,对车辆进行加速/减速操作,输出加减速后的车辆基本信息。
**
请问该如何把调用加速和减速方法**
internal class Program
{
static void Main(string[] args)
{
Vehicle car1 = new Vehicle ("川A66666","白色","50");
car1.Output();
int speed = SByte.Parse (car1.Speed);
int speed1=car1.speedup(ref speed );
car1.Output();
car1.speeddown(ref speed);
car1.Output();
Console.ReadKey ();
}
}
///
/// 机车类
///
class Vehicle
{
public const string highspeed= "200";//常量 最高速度
private string _No;//字段 车牌号
private string _Color;//字段 车辆颜色
private string _Speed;//字段 行驶速度
public Vehicle(string No,string Color,string Speed) //构造函数,初始化初段值
{
_No = No;
_Color = Color;
_Speed = Speed;
}
public string No //属性
{
get
{
return _No;
}
set
{
_No = value;
}
}
public string Color
{
get
{
return _Color;
}
set
{
_Color = value;
}
}
public string Speed
{
get
{
return _Speed;
}
set
{
_Speed = value;
}
}
///方法 车辆加速方法
public int speedup(ref int speed1)//车辆加速
{
int Speed1= Convert.ToInt32(Speed );
speed1 = Speed1 + 10;
return (int)speed1;
}
public int speeddown(ref int speed2)//车辆减速
{
int Speed1 = Convert.ToInt32(Speed);
speed2 = Speed1 - 10;
return speed2;
}
public void Output()
{
Console.WriteLine("{0},{1},{2}", No, Color, Speed);
}
}
把方法放到这个里面 这个是程序的入口 static void Main(string[] args)