Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace UzdizTest
  5. {
  6.     internal class Program
  7.     {
  8.         private static void Main(string[] args)
  9.         {
  10.             // Create a tree structure
  11.  
  12.             var root = new TvKuca();
  13.            
  14.  
  15.             var prog1 = new TvProgram
  16.             {
  17.                 Naziv = "Program 1",
  18.                 Pocetak = DateTime.Parse("8:00"),
  19.                 Kraj =  DateTime.Parse("23:00")
  20.             };
  21.          
  22.  
  23.             var comp = new DnevniRaspored
  24.             {
  25.                 Dan = 1
  26.             };
  27.             comp.Add(new StavkaRasporeda
  28.             {
  29.                 IdEmisije = 1,
  30.                 NazivEmisije = "Emisija",
  31.                 Pocetak = DateTime.Parse("9:00"),
  32.                 Kraj = DateTime.Parse("10:20")
  33.             });
  34.            
  35.             comp.Add(new StavkaRasporeda
  36.             {
  37.                 IdEmisije = 2,
  38.                 NazivEmisije = "DrugaEmisija",
  39.                 Pocetak = DateTime.Parse("12:00"),
  40.                 Kraj = DateTime.Parse("14:00")
  41.             });
  42.  
  43.             prog1.Add(comp);
  44.             root.Add(prog1);
  45.  
  46.             // Recursively display tree
  47.  
  48.             root.Display(1);
  49.  
  50.         }
  51.     }
  52.  
  53.     abstract class Component
  54.     {
  55.         //protected string name;
  56.  
  57.         // Constructor
  58.  
  59.         //public Component(string name)
  60.         //{
  61.         //    this.name = name;
  62.         //}
  63.  
  64.         public abstract void Add(Component c);
  65.         public abstract void Remove(Component c);
  66.         public abstract void Display(int depth);
  67.     }
  68.  
  69.     class TvKuca : Component
  70.     {
  71.  
  72.         private readonly List<Component> _children = new List<Component>();
  73.  
  74.         // Constructor
  75.  
  76.         //public TvProgram(string name)
  77.         //    : base(name)
  78.         //{
  79.         //}
  80.  
  81.         public override void Add(Component component)
  82.         {
  83.             _children.Add(component);
  84.         }
  85.  
  86.         public override void Remove(Component component)
  87.         {
  88.             _children.Remove(component);
  89.         }
  90.  
  91.         public override void Display(int depth)
  92.         {
  93.             Console.WriteLine(new string('-', depth) + "TV kuća");
  94.  
  95.             // Recursively display child nodes
  96.  
  97.             foreach (var component in _children)
  98.             {
  99.                 component.Display(depth + 2);
  100.             }
  101.         }
  102.     }
  103.  
  104.  
  105.     class TvProgram : Component
  106.     {
  107.         public string Naziv { get; set; }
  108.         public DateTime Pocetak { get; set; }
  109.         public DateTime Kraj { get; set; }
  110.  
  111.         private readonly List<Component> _children = new List<Component>();
  112.  
  113.         // Constructor
  114.  
  115.         //public TvProgram(string name)
  116.         //    : base(name)
  117.         //{
  118.         //}
  119.  
  120.         public override void Add(Component component)
  121.         {
  122.             _children.Add(component);
  123.         }
  124.  
  125.         public override void Remove(Component component)
  126.         {
  127.             _children.Remove(component);
  128.         }
  129.  
  130.         public override void Display(int depth)
  131.         {
  132.             Console.WriteLine(new string('-', depth) + $"TV Program {Naziv} ({Pocetak.ToShortTimeString()} - {Kraj.ToShortTimeString()})");
  133.  
  134.             // Recursively display child nodes
  135.  
  136.             foreach (var component in _children)
  137.             {
  138.                 component.Display(depth + 2);
  139.             }
  140.         }
  141.     }
  142.  
  143.     class DnevniRaspored : Component
  144.     {
  145.         public int Dan { get; set; }
  146.  
  147.         private readonly List<Component> _children = new List<Component>();
  148.  
  149.         // Constructor
  150.  
  151.         //public DnevniRaspored(string name)
  152.         //    : base(name)
  153.         //{
  154.         //}
  155.  
  156.         public override void Add(Component component)
  157.         {
  158.             _children.Add(component);
  159.         }
  160.  
  161.         public override void Remove(Component component)
  162.         {
  163.             _children.Remove(component);
  164.         }
  165.  
  166.         public override void Display(int depth)
  167.         {
  168.             Console.WriteLine(new string('-', depth) + $"Raspored za {(Dan)Dan}");
  169.  
  170.             // Recursively display child nodes
  171.  
  172.             foreach (var component in _children) component.Display(depth + 2);
  173.         }
  174.     }
  175.  
  176.  
  177.     class StavkaRasporeda : Component
  178.     {
  179.         // id; dani u tjednu (1-pon);početak;osoba-uloga,osoba-uloga,...
  180.  
  181.         public int IdEmisije { get; set; }
  182.         public string NazivEmisije { get; set; }
  183.         public DateTime Pocetak { get; set; }
  184.         public DateTime Kraj { get; set; }
  185.  
  186.         // Constructor
  187.  
  188.         //public StavkaRasporeda(string name)
  189.         //    : base(name)
  190.         //{
  191.         //}
  192.  
  193.         public override void Add(Component c)
  194.         {
  195.             Console.WriteLine("Cannot add to a leaf");
  196.         }
  197.  
  198.         public override void Remove(Component c)
  199.         {
  200.             Console.WriteLine("Cannot remove from a leaf");
  201.         }
  202.  
  203.         public override void Display(int depth)
  204.         {
  205.             Console.WriteLine(new string('-', depth) + $"Emisija {NazivEmisije} ({Pocetak.ToShortTimeString()} - {Kraj.ToShortTimeString()})");
  206.         }
  207.     }
  208.  
  209.     public enum Dan {
  210.         ponedjeljak,
  211.         utorak,
  212.         srijeda,
  213.         četvrtak,
  214.         petak,
  215.         subota,
  216.         nedjelja
  217.     }
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement