1、封装一个类:Aircraft,拥有属性:牌子、型号、颜色、隶属公司、飞行速度、装载人数、飞机类型(大中小(400-200-100)由装载人数自动设置)、当前飞机装载的人数(随机生成)
cs
using System.Drawing;
namespace _1
{
internal class Program
{
static void Main(string[] args)
{
//1.封装一个类:Aircraft,拥有属性:牌子、型号、颜色、隶属公司、飞行速度、装载人数、飞机类型(大中小(400-200-100)由装载人数自动设置)、当前飞机装载的人数(随机生成)
Aircraft Air=new Aircraft ("空客 (Airbus)", "A350 XWB","白色", "宇航",500);
Air.random(); //随机生成当前飞机装载的人数
Air.Judge(); //判断使用的飞机类型
Air.Show(); //打印
Aircraft Air1 = new Aircraft("安东诺夫(Antonov)", "An-124", "蓝色", "乌克兰军事航空", 400);
Air1.random(); //随机生成当前飞机装载的人数
Air1.Judge(); //判断使用的飞机类型
Air1.Show(); //打印
}
}
class Aircraft
{
public string PZ; //飞机牌子
public string Model; //飞机型号
public string Color; //飞机颜色
public string Company; //飞机隶属公司
public double Speed; //飞机飞行速度
public int People; //飞机装载人数
public int Now_People; //当前飞机装载的人数
public enum Etype //飞机类型枚举
{
大 = 400, 中 = 200, 小 = 100
}
public Etype Type; //飞机类型
public Aircraft(string pZ, string model, string color, string company, double speed)
{
PZ = pZ;
Model = model;
Color = color;
Company = company;
Speed = speed;
}
public void random()
{
Random n = new Random();
Now_People = n.Next(0, 401);
}
public void Judge()
{
if (Now_People <= 100)
{
Type = Aircraft.Etype.小;
}
else if (Now_People > 200)
{
Type = Aircraft.Etype.大;
}
else
{
Type = Aircraft.Etype.中;
}
People = (int)Type;
}
public void Show()
{
Console.WriteLine($"飞机的牌子{PZ}、型号{Model}、颜色{Color}、隶属公司{Company}、飞行速度{Speed}km/h、装载人数{People}、飞机类型{Type}型、当前飞机装载的人数{Now_People}");
}
}
}