當前位置:編程學習大全網 - 編程軟體 - C#編程求助,圖片上的程序應該怎麽編程,求助大咖給壹個完整的程序代碼,謝謝謝謝

C#編程求助,圖片上的程序應該怎麽編程,求助大咖給壹個完整的程序代碼,謝謝謝謝

采納吧

using?System;

namespace?ConsoleApplication1

{

class?Program

{

static?void?Main(string[]?args)

{

var?passtrain?=?new?Passtrain(1500,"88888888",220);

Console.WriteLine(passtrain.GetMessage());//?顯示客車信息

passtrain.IsSpeeding(180);//?判斷速度是否超過180

//?輸出內容:

//?客車重量:1500?車牌號:88888888?當前速度:220

//?您已超速!

Console.ReadLine();

}

interface?IPasstrain

{

int?Weight?{?get;?set;?}

string?Plate?{?get;?set;?}

int?NowV?{?get;?set;?}

string?GetMessage();

}

public?class?Passtrain?:?IPasstrain

{

public?int?Weight?{?get;?set;?}

public?string?Plate?{?get;?set;?}

public?int?NowV?{?get;?set;?}

///?<summary>

///?當超速時觸發的事件

///?</summary>

event?Action?SpeedingEventHandler?=?()?=>?{?Console.WriteLine("您已超速!");?};

public?string?GetMessage()

{

return?$"客車重量:{Weight}?車牌號:{Plate}?當前速度:{NowV}";

}

///?<summary>

///?判斷是否超速

///?</summary>

///?<param?name="setSpeeding">限定速度</param>

public?void?IsSpeeding(int?setSpeeding)

{

if?(this.NowV?>?setSpeeding)

{

SpeedingEventHandler();

}

}

public?Passtrain(int?weight,?string?plate,?int?nowV)

{

this.Weight?=?weight;

this.Plate?=?plate;

this.NowV?=?nowV;

}

}

}

}

  • 上一篇:fpga工程師有中年危機嗎?
  • 下一篇:3d建模怎麽學
  • copyright 2024編程學習大全網