参考:
AwardSuper.cs
using System; using System.Collections.Generic; using System.Text; namespace StrategyMode { abstract class AwardSuper
{ public abstract string Award(double courseMark,double moralMark,double gymMark); } }
ThreeGoodAward.cs
using System; using System.Collections.Generic; using System.Text; namespace StrategyMode { class ThreeGoodAward : AwardSuper { public override string Award(double courseMark,double moralMark,double gymMark) { if (courseMark >= 80 && moralMark >= 80 && gymMark >= 80) return "三好学生"; else return ""; } } }
CourseAward.cs
using System; using System.Collections.Generic; using System.Text; namespace StrategyMode { class CourseAward :AwardSuper { public override string Award(double courseMark, double moralMark, double gymMark) { if (courseMark >= 80) return "课程奖"; else return ""; } } }
MoralAward.cs:
using System; using System.Collections.Generic; using System.Text; namespace StrategyMode { class MoralAward :AwardSuper { public override string Award(double courseMark, double moralMark, double gymMark) { if (moralMark >= 90 && moralMark >= 60&&gymMark >= 60) return "道德奖"; else return ""; } } }
AwardContext.cs:
using System; using System.Collections.Generic; using System.Text; namespace StrategyMode { class AwardContext { private AwardSuper aws; public AwardContext(AwardSuper asuper) { this.aws=asuper; } public string GetResult(double courseMark, double moralMark, double gymMark) { return aws.Award(courseMark,moralMark,gymMark); } }
}
Program.cs:
using System; namespace StrategyMode { class Program { static void Main(string[] args) { AwardContext cc = null; string strSel = string.Empty; Console.WriteLine("请选择奖励种类:"); strSel=Console.ReadLine(); switch(strSel) { case "three": cc = new AwardContext(new ThreeGoodAward()); break; case "course": cc = new AwardContext(new CourseAward()); break; case "moral": cc = new AwardContext(new MoralAward()); break; } Console.WriteLine("请输入Course Mark:"); string courseMark = Console.ReadLine(); Console.WriteLine("请输入Moral Mark:"); string moralMark = Console.ReadLine(); Console.WriteLine("请输入Gym Mark:"); string gymMark = Console.ReadLine(); string strResult = cc.GetResult(Convert.ToDouble(courseMark),Convert.ToDouble(moralMark), Convert.ToDouble(gymMark)); Console.WriteLine(strResult); } } }
标签:演示,策略,double,courseMark,moralMark,System,模式,using,string From: https://www.cnblogs.com/exesoft/p/16721192.html