?? car.cs
字號:
using System;
using System.Collections.Generic;
using System.Text;
namespace Chapter35
{
class Car
{
private int _百公里耗油 = 10;
private int _油箱容積 = 60;
private int _油表;
private int _公里數;
public int 百公里耗油
{
get { return 百公里耗油; }
}
public int 油箱容積
{
get { return _油箱容積; }
}
public int 油表
{
get { return _油表; }
set { _油表 = value; }
}
public int 公里數
{
get { return _公里數; }
set { _公里數 = value; }
}
public Car()
{
_油表 = _油箱容積;
_公里數 = 0;
}
public Car(int 當前油表)
{
_油表 = 當前油表;
_公里數 = 0;
}
public Car(int 當前油表,int 當前里程)
{
_油表 = 當前油表;
_公里數 = 當前里程;
}
private int 計算耗油(int 行駛公里數)
{
return 行駛公里數 * _百公里耗油 / 100;
}
public void 行駛(int 行駛公里數)
{
Console.WriteLine("行駛{0}公里開始", 行駛公里數);
if (_油表 > 計算耗油(行駛公里數))
{
_公里數 += 行駛公里數;
_油表 -= 計算耗油(行駛公里數);
Console.WriteLine("行駛完畢");
}
else
Console.WriteLine("油耗不足,行駛失敗");
}
public void 加油()
{
Console.WriteLine("加油開始");
int 需要加的油 = _油箱容積 - _油表;
_油表 += 需要加的油;
Console.WriteLine("加油完畢,一共加了 {0} 升", 需要加的油);
}
public void 加油(int 加油體積)
{
Console.WriteLine("加油{0}升開始", 加油體積);
if (加油體積 < _油箱容積)
{
_油表 += 加油體積;
Console.WriteLine("加油完畢");
}
else
Console.WriteLine("超過最大油箱容積,加油失敗");
}
public void 獲取當前汽車信息()
{
Console.WriteLine(string.Format("當前油表:{0} 當前里程數:{1}", _油表, _公里數));
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -