Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace UzdizTest
- {
- internal class Program
- {
- private static void Main(string[] args)
- {
- // Create a tree structure
- var root = new TvKuca();
- var prog1 = new TvProgram
- {
- Naziv = "Program 1",
- Pocetak = DateTime.Parse("8:00"),
- Kraj = DateTime.Parse("23:00")
- };
- var comp = new DnevniRaspored
- {
- Dan = 1
- };
- comp.Add(new StavkaRasporeda
- {
- IdEmisije = 1,
- NazivEmisije = "Emisija",
- Pocetak = DateTime.Parse("9:00"),
- Kraj = DateTime.Parse("10:20")
- });
- comp.Add(new StavkaRasporeda
- {
- IdEmisije = 2,
- NazivEmisije = "DrugaEmisija",
- Pocetak = DateTime.Parse("12:00"),
- Kraj = DateTime.Parse("14:00")
- });
- prog1.Add(comp);
- root.Add(prog1);
- // Recursively display tree
- root.Display(1);
- }
- }
- abstract class Component
- {
- //protected string name;
- // Constructor
- //public Component(string name)
- //{
- // this.name = name;
- //}
- public abstract void Add(Component c);
- public abstract void Remove(Component c);
- public abstract void Display(int depth);
- }
- class TvKuca : Component
- {
- private readonly List<Component> _children = new List<Component>();
- // Constructor
- //public TvProgram(string name)
- // : base(name)
- //{
- //}
- public override void Add(Component component)
- {
- _children.Add(component);
- }
- public override void Remove(Component component)
- {
- _children.Remove(component);
- }
- public override void Display(int depth)
- {
- Console.WriteLine(new string('-', depth) + "TV kuća");
- // Recursively display child nodes
- foreach (var component in _children)
- {
- component.Display(depth + 2);
- }
- }
- }
- class TvProgram : Component
- {
- public string Naziv { get; set; }
- public DateTime Pocetak { get; set; }
- public DateTime Kraj { get; set; }
- private readonly List<Component> _children = new List<Component>();
- // Constructor
- //public TvProgram(string name)
- // : base(name)
- //{
- //}
- public override void Add(Component component)
- {
- _children.Add(component);
- }
- public override void Remove(Component component)
- {
- _children.Remove(component);
- }
- public override void Display(int depth)
- {
- Console.WriteLine(new string('-', depth) + $"TV Program {Naziv} ({Pocetak.ToShortTimeString()} - {Kraj.ToShortTimeString()})");
- // Recursively display child nodes
- foreach (var component in _children)
- {
- component.Display(depth + 2);
- }
- }
- }
- class DnevniRaspored : Component
- {
- public int Dan { get; set; }
- private readonly List<Component> _children = new List<Component>();
- // Constructor
- //public DnevniRaspored(string name)
- // : base(name)
- //{
- //}
- public override void Add(Component component)
- {
- _children.Add(component);
- }
- public override void Remove(Component component)
- {
- _children.Remove(component);
- }
- public override void Display(int depth)
- {
- Console.WriteLine(new string('-', depth) + $"Raspored za {(Dan)Dan}");
- // Recursively display child nodes
- foreach (var component in _children) component.Display(depth + 2);
- }
- }
- class StavkaRasporeda : Component
- {
- // id; dani u tjednu (1-pon);početak;osoba-uloga,osoba-uloga,...
- public int IdEmisije { get; set; }
- public string NazivEmisije { get; set; }
- public DateTime Pocetak { get; set; }
- public DateTime Kraj { get; set; }
- // Constructor
- //public StavkaRasporeda(string name)
- // : base(name)
- //{
- //}
- public override void Add(Component c)
- {
- Console.WriteLine("Cannot add to a leaf");
- }
- public override void Remove(Component c)
- {
- Console.WriteLine("Cannot remove from a leaf");
- }
- public override void Display(int depth)
- {
- Console.WriteLine(new string('-', depth) + $"Emisija {NazivEmisije} ({Pocetak.ToShortTimeString()} - {Kraj.ToShortTimeString()})");
- }
- }
- public enum Dan {
- ponedjeljak,
- utorak,
- srijeda,
- četvrtak,
- petak,
- subota,
- nedjelja
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement