OJ Problem 3491 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),用来输出信息,具体格式如下描述。 

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

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

扫描二维码关注公众号,回复: 13086626 查看本文章

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());
        }
    }

输入

输出

样例输入

样例输出

Trademark:Ford,Color:Grey,Load:1.8
The car started
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.IO;
namespace ConsoleApplication1
{
    abstract class Vehicles
    {
        /
        private string brand;
        private string color;
        public string Brand
        {
            get
            {
                return brand;
            }
            set
            {
                brand = value;
            }
        }
        public string Color
        {
            get
            {
                return color;
            }
            set
            {
                color = value;
            }
        }
        public abstract string run();
    }
    class Car : Vehicles
    {
        private double load;
        public double Load
        {
            get
            {
                return load;
            }
            set
            {
                load = value;
            }
        }
        public override string run()
        {
            return "The car started";
        }
        public string getInfo(Car car)
        {
            string ans="Trademark:"+car.Brand+",Color:"+car.Color+",Load:"+car.load;
            return ans;
        }
        /
    }
    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());

        }
    }
} 

猜你喜欢

转载自blog.csdn.net/wangws_sb/article/details/105155330