//先 写出 1个 父类 2个子类
///
/// 父类
///
public abstract class Vehicle
{
//颜色
public string Color{get;set;}
//日租金
public double DailyRent { get; set; }
//车牌号
public string LicenseNO { get; set; }
//车名
public string Name { get; set; }
//租车日期
public int RentDate {get; set; }
//租车人
public string RentUser { get; set; }
//使用时间
public int YearsOFService { get; set; }
/// 计算价格的方法
public abstract double CalcPrice();
public Vehicle() { }
public Vehicle(string color, double dailyrent, string licenseno, string name, int rentdate, string rentuser, int yearsofservice)
{
this.Color = color;
this.DailyRent = dailyrent;
this.LicenseNO = licenseno;
this.Name = name;
this.RentDate = rentdate;
this.RentUser = rentuser;
this.YearsOFService = yearsofservice;
}
}
//继承 为多态做准备 卡车类
class Truck : Vehicle
{
//载重
public int Load { get; set; }
public Truck() { }
public Truck(string color, double dailyrent, string licenseno, string name, int rentdate, string rentuser, int yearsofservice, int load)
: base(color, dailyrent, licenseno, name, rentdate, rentuser, yearsofservice)
{
this.Load = load;
}
///
/// 卡车费用计算方法
/// 30天以内(含30)按日租金计算
/// 30天以上超出部分:每天,每吨(载重量)增加日租金10%
///
public override double CalcPrice()
{
double totalPrice = 0;
double basicPrice = this.RentDate * this.DailyRent;
if (this.RentDate <= 30)
{
totalPrice = basicPrice;
}
else
{
//30天以上超出部分:每天,每吨(载重量)增加日租金10%
totalPrice = basicPrice + (this.RentDate - 30) * this.Load * this.DailyRent