using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sj4
{
class Program
{
static void Main(string[] args)
{
bus b1 = new bus("红色", "高雅巴士", 20);
bus b2 = new bus("蓝色", "高雅巴士", 10);
bus b3 = new bus("绿色", "高雅巴士", 30);
truck t1 = new truck("黄色", 30, "大象");
truck t2 = new truck("绿色", 25, "大象");
truck t3 = new truck("金色", 20, "大象");
mini_truck mt1 = new mini_truck("金色", 10, "小象");
mini_truck mt2 = new mini_truck("红色", 10, "小象");
List<vehicle> vehicleBox = new List<vehicle>();
vehicleBox.Add(b1);
vehicleBox.Add(b2);
vehicleBox.Add(b3);
vehicleBox.Add(t1);
vehicleBox.Add(t2);
vehicleBox.Add(t3);
vehicleBox.Add(mt1);
vehicleBox.Add(mt2);
for (int i = 0; i < vehicleBox.Count; i++)
{
if (vehicleBox[i] is bus)
{
bus b = (bus)(vehicleBox[i]);
b.Run();
}
if (vehicleBox[i] is truck)
{
truck t = (truck)(vehicleBox[i]);
t.Run();
}
if (vehicleBox[i] is mini_truck)
{
mini_truck mt = (mini_truck)(vehicleBox[i]);
mt.Run();
}
}
}
}
class bus:vehicle
{
public bus() { }
public bus(string color,string name,int passengernum): base(color,name,passengernum)
{
;
}
public override void Run()
{
string mes = string.Format("{0}颜色的{1}公共汽车,乘客{2}名",base.Color,base.Name,base.Passengernum);
Console.WriteLine(mes);
}
}
class truck:vehicle
{
public truck() { }
public truck(string color, int load, string name): base(color,load,name)
{
;
}
public override void Run()
{
string mes = string.Format("{0}颜色的{1}货车,载重{2}吨",base.Color,base.Name,base.Load);
Console.WriteLine(mes);
}
}
class mini_truck:truck
{
public mini_truck() { }
public mini_truck(string color, int load, string name): base(color,load,name)
{
;
}
public void Run()
{
string mes = string.Format("{0}颜色的{1}小货车,载重{2}吨", base.Color, base.Name, base.Load);
Console.WriteLine(mes);
}
}
/// <summary>
/// 交通工具爹类
/// </summary>
abstract class vehicle
{
public vehicle() { }
public vehicle(string color, string name, int passengernum)
{
this.color = color;
this.name = name;
this.passengernum = passengernum;
}
public vehicle(string color,int load,string name)
{
this.color = color;
this.name = name;
this.load = load;
}
private string color;
private string name;
private int passengernum;
private int load;
public int Load
{
get { return load; }
set { load = value; }
}
public int Passengernum
{
get { return passengernum; }
set { passengernum = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public string Color
{
get { return color; }
set { color = value; }
}
public abstract void Run();
}
}