怎么创建类,编写方法和继承啊?

用c#程序建立一个汽车Auto类,包括轮胎个数、汽车颜色、车身重量、速度等属性,并通过不同的构造方法创建实例,要求汽车能够启动、加速、减速、停车。再定义一个小汽车类Car继承Auto,并添加空调、CD等成员变量,重写加速、减速的方法,增加显示汽车当前状态的输出方法(输出基本信息和行驶状态,如颜色、车重、当前速度)。在Main()方法中、分别实例化这两个子类,然后分别调用启动、加速和减速方法,并输出当前状况。
 

这样? 帮助到你可以点击采纳吗,谢谢~~

using System;
namespace ConsoleApp1
{
    class Auto
    {
        public bool started { get; set; }
        public int Tyres { get; set; }
        public string Color { get; set; }
        public double Weight { get; set; }
        public double Speed { get; set; }
        public void AddSpeed(double value) { this.Speed += value; }
        public void MinusSpeed(double value) { if (this.Speed >= value) this.Speed -= value; else this.Speed = 0; }
        public void Stop() { this.Speed = 0;this.started = false; }
        public void Start() { this.Speed = 1; this.started = true; }
    }
    class Car : Auto
    {
        public string Aircondition { get; set; }
        public string Cd { get; set; }
        public new void AddSpeed(double value) { this.Speed += value; }
        public new void MinusSpeed(double value) { if (this.Speed >= value) this.Speed -= value; else this.Speed = 0; }
        public void ShowState()
        {
            Console.WriteLine("状态:"+(this.started?"启动":"停止")+"\t轮胎数:"+Tyres + "\t颜色:" + Color + "\t重量:" + Weight + "吨\t速度:" + Speed );
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var car = new Car { Tyres = 4, Color = "白色", Weight = 1.3, Speed = 0, Aircondition = "松下", Cd = "Sony" };
            car.Start();
            car.ShowState();
            car.AddSpeed(10);
            car.ShowState();
            car.AddSpeed(60);
            car.ShowState();
            car.MinusSpeed(30);
            car.ShowState();
            car.Stop();
            car.ShowState();

            Console.ReadKey();

        }
    }
}

 

额,你这不是都说出来了

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632