zoukankan      html  css  js  c++  java
  • 问题 A: C#抽象类Vehicles

    题目描述

    一、定义一个抽象类Vehicles,具体要求如下:

    1、私有字段商标brand(string)、颜色color(string)。

    2、定义公有读写属性Brand用来访问brand字段;定义公有读写属性Color用来访问color字段。

    3、设计一个抽象虚方法run()。

    二、定义Vehicles类的子类Car,具体要求如下:

    1、私有字段载重load(double)。

    2、定义公有读写属性Load用来访问load字段。

    3、重写抽象方法run(),用来输出信息“Car开动了”。

    4、设计一个方法getInfo(Car car),用来输出信息,具体格式如下描述。

       商标:***, 颜色:***,载重:***。

    根据以下代码,请补写缺失的代码。

    using System;
    namespace ConsoleApplication1
    {

        abstract class Vehicles
        {

     
    /////////////////////////////////////////////////////////////////

       //请填写代码

    /////////////////////////////////////////////////////////////////
     

        }
        class Program
        {
            static void Main(string[] args)
            {
                Car car = new Car();
                car.Brand = "Ford";
                car.Color = "Grey";
                car.Load = 1.8;

                Console.WriteLine(car.getInfo(car));
                Console.WriteLine(car.run());

            }
        }
    }

     





    输入

    输出

     

    样例输入

    .wrapper {position: relative;} #input {position: absolute;top: 0;left: 0;opacity: 0;z-index: -10;}

    样例输出

    Trademark:Ford,Color:Grey,Load:1.8
    The car started
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace 抽象类Vehicle
    {
            abstract class Vehicles
            {
                private string brand;
                private string color;
                public string Brand { set { this.brand = value; } get { return brand; } }
                public string Color { set { this.color = value; } get { return color; } }
                public abstract string run();
            }
            class Car : Vehicles
            {
                private double load;
                public double Load { set { this.load = value; } get { return load; } }
                public override string run()
                {
    
                    return "The car started";
                }
    
                public string getInfo(Car car)
                {
                    return "Trademark:" + Brand + "," + "Color:" + Color + "," + "Load:" + Load;
                }
            }
    
    
            class Program
            {
                static void Main(string[] args)
                {
                    Car car = new Car();
                    car.Brand = "Ford";
                    car.Color = "Grey";
                    car.Load = 1.8;
    
                    Console.WriteLine(car.getInfo(car));
                    Console.WriteLine(car.run());
                    Console.ReadKey();
                }
            }
    }
    

      

    注意提交的格式

         private string brand;
            private string color;
            public string Brand { set { this.brand = value; } get { return brand; } }
            public string Color { set { this.color = value; } get { return color; } }
            public abstract string run();
          }
            class Car : Vehicles
            {
                private double load;
                public double Load { set { this.load = value; } get { return load; } }
                public override string run()
                {
    
                    return "The car started";
                }
    
                public string getInfo(Car car)
                {
                    return "Trademark:" + Brand + "," + "Color:" + Color + "," + "Load:" + Load;
                }
    

      

  • 相关阅读:
    问题:使用pandas中的DataFrame写入csv文件多出一行unnamed,如何解决呢??
    使用pandas进行数据分析-pandas库介绍之DataFrame基本操作
    【USACO 2017 February Gold】Problem 3. Why Did the Cow Cross the Road III
    JZOJ【USACO 2017 December Silver】Milk Measurement
    JZOJ.2020.05.23【NOIP提高组】模拟(反思)
    PRIM+KRUSKAL
    draggable
    easyUI使用的两种方法
    MySQL 常见函数
    jdbc,hibernate,mybatis调用存储过程
  • 原文地址:https://www.cnblogs.com/mjn1/p/12618840.html
Copyright © 2011-2022 走看看