贾维
新成员
- 已加入
- 2021年1月21日
- 留言内容
- 1
- 编程经验
- Beginner
您正在创建一个绘图应用程序,当前只有一种工具-铅笔。您要向绘图工具栏添加画笔和喷涂。
给出的程序声明一个 画图 与 StartDraw() 方法和类 画 ,它通过实现IDraw接口执行铅笔绘图。它输出"Using pencil".
通过完成以下给定的刷子和喷雾类
-从Draw类继承它们
-为每个工具实现StartDraw()方法,以便输出
"Using brush" 用于刷子,或
"Using spray" 喷雾。
画 对象及其方法调用在Main()中提供。
给出的程序声明一个 画图 与 StartDraw() 方法和类 画 ,它通过实现IDraw接口执行铅笔绘图。它输出"Using pencil".
通过完成以下给定的刷子和喷雾类
-从Draw类继承它们
-为每个工具实现StartDraw()方法,以便输出
"Using brush" 用于刷子,或
"Using spray" 喷雾。
画 对象及其方法调用在Main()中提供。
C#:
using System;
using System.Collections.Generic;
namespace Code_Coach_Challenge
{
class Program
{
static void Main(string[] args)
{
画 pencil = new 画 ();
画 brush = new Brush();
画 spray = new Spray();
pencil.StartDraw();
brush.StartDraw();
spray.StartDraw();
}
}
/*
画 => "Using pencil"
Brush => "Using brush"
Spray => "Using spray"
*/
public interface 画图
{
void StartDraw() ;
}
class 画 : 画图
{
public virtual void StartDraw()
{
Console.WriteLine("Using pencil");
}
}
//inherit this class from the class 画
class Brush
{
//implement the StartDraw() method
}
//inherit this class from the class 画
class Spray
{
//implement the StartDraw() method
}
}
由主持人最后编辑: