axeefectushka

Untitled

Nov 3rd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.  
  8.         Training timetable1 = new Training("First Training");
  9.  
  10.         Console.WriteLine(timetable1.IsPractical());
  11.  
  12.         timetable1.Add(new Practice("Practical lesson 1.", "Demonstrate Inheritance using multiple classes.", "Lecture 1. Inheritance"));
  13.  
  14.         Console.WriteLine(timetable1.IsPractical());
  15.  
  16.         timetable1.Add(new Lecture("Lecture 1.", "Inheritance"));
  17.  
  18.         Console.WriteLine(timetable1.IsPractical());
  19.     }
  20. }
  21.  
  22. abstract class TrainingManagement
  23. {
  24.     public string Description { get; set; }
  25.  
  26.     protected TrainingManagement(string description)
  27.     {
  28.      Description = description;
  29.     }
  30.  
  31. class Training : TrainingManagement
  32. {
  33.     private Lesson[] _timetable;
  34.  
  35.     public Training(string description):base(description)
  36.     {
  37.         _timetable = new Lesson[0];
  38.     }
  39.  
  40.     public void Add(Lesson lesson)
  41.     {
  42.         if (lesson != null)
  43.         {
  44.             Array.Resize(ref _timetable, _timetable.Length + 1);
  45.  
  46.             _timetable[_timetable.Length - 1] = lesson;
  47.  
  48.         }
  49.     }
  50.  
  51.     public bool IsPractical()
  52.     {
  53.         if (_timetable == null || _timetable.Length==0) return false;
  54.         else
  55.         {
  56.             foreach(Lesson item in _timetable)
  57.             {
  58.                 if (item as Practice == null) return false;
  59.             }
  60.         }
  61.         return true;
  62.     }
  63.  
  64. }
  65.  
  66. abstract class Lesson : TrainingManagement
  67. {
  68.     protected Lesson(string description) : base(description) { }
  69.    
  70. }
  71. class Lecture : Lesson
  72. {
  73.     public string Theme { get; set; }
  74.  
  75.     public Lecture(string description, string theme): base(description)
  76.     {
  77.         Theme = theme;
  78.     }
  79. }
  80.  
  81. class Practice : Lesson
  82. {
  83.     public string TaskCondition { get; set; }
  84.  
  85.     public string SolutionCondition { get; set; }
  86.  
  87.     public Practice(string description, string task, string solution): base(description)
  88.     {
  89.         TaskCondition = task;
  90.  
  91.         SolutionCondition = solution;
  92.     }
  93. }
Add Comment
Please, Sign In to add comment