From 8c5fe273999c9f8bc03526307e910bb5a0a0ab8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=86=AC=E9=9D=99?= <10036377+huang-dongjing@user.noreply.gitee.com> Date: Fri, 29 Apr 2022 03:53:59 +0000 Subject: [PATCH] =?UTF-8?q?27=E9=BB=84=E5=86=AC=E9=9D=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...45\345\217\243\344\275\234\344\270\232.md" | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 "27\351\273\204\345\206\254\351\235\231/\346\216\245\345\217\243\344\275\234\344\270\232.md" diff --git "a/27\351\273\204\345\206\254\351\235\231/\346\216\245\345\217\243\344\275\234\344\270\232.md" "b/27\351\273\204\345\206\254\351\235\231/\346\216\245\345\217\243\344\275\234\344\270\232.md" new file mode 100644 index 0000000..1173fdb --- /dev/null +++ "b/27\351\273\204\345\206\254\351\235\231/\346\216\245\345\217\243\344\275\234\344\270\232.md" @@ -0,0 +1,113 @@ +接口作业 + +一、 + +主方法: + +namespace JK +{ +//一、编写一个程序以实现家用电器的层次结构, +//此层次结构将包含电器ElectricEquipment抽象类和空调类AirCondition。 +//ElectricEquipment类应包含一个表示电器工作的Working()方法, +//该方法应该在子类中被实现。 + class Program + { + static void Main(string[] args) + { + ElectricEquipment a = new Aircondition(); + a.Working(); + } + } +} + +类: + +namespace JK +{ + //一、编写一个程序以实现家用电器的层次结构, + //此层次结构将包含电器ElectricEquipment抽象类和空调类AirCondition。 + //ElectricEquipment类应包含一个表示电器工作的Working()方法, + //该方法应该在子类中被实现。 + abstract class ElectricEquipment + { + public abstract void Working(); + } + class Aircondition: ElectricEquipment + { + public override void Working() + { + + Console.WriteLine("电器正常运转"); + } + } +} + +二、 + +主方法: + +namespace LX2 +{ + class Program + { + static void Main(string[] args) + { + ICard a = new A() { time = 2}; + a.Getout(); + ICard b = new B() { time = 5}; + b.Getout(); + } + } +} + +类: + +namespace LX2 +{ +// 二、 定义一个接口,接口名为ICard,其中定义一个成员方法,方法名自定义,方法要实现的功能是对电话卡进行扣款。 +//定义两个子类,实现ICard接口,实现其中的扣款方法,一个类实现201卡(前3分钟0.2元,之后每分钟0.1元)的扣款功能,一个类实现校园卡(每分钟0.1元)的扣款功能,每个类有一个成员变量banlance保存余额,默认为100。 + + interface ICard + { + void Getout(); + } + class kk + { + public double time { get; set; } + public double banlance = 100; + } + //实现201卡 + + class A :kk,ICard + { + public void Getout() + { + + if (time<=3) + { + banlance = banlance - time * 0.2; + Console.WriteLine("余额为:{0}",banlance); + } + else + { + banlance = banlance - time * 0.1-0.6; + Console.WriteLine("余额为:{1}", banlance); + } + + } + } + //实现校园卡 + class B :kk,ICard + { + public void Getout() + { + banlance = banlance - time * 0.1; + Console.WriteLine("余额为:{0}", banlance); + } + } +} + +```c#c + +``` + -- Gitee