Beispiel #1
0
        static void Main(string[] args)
        {
            TVProgram[] programs = new TVProgram[5];

            programs[0] = new Film();
            programs[1] = new Cartoon();
            programs[2] = new News();
            programs[3] = new Advertising();
            programs[4] = new Advertising();

            programs[0].Duration       = 5;
            programs[0].ProductionYear = 2000;
            programs[1].Duration       = 6;
            programs[1].ProductionYear = 2011;
            programs[2].Duration       = 3;
            programs[2].ProductionYear = 2005;
            programs[3].Duration       = 2;
            programs[3].ProductionYear = 1986;
            programs[4].Duration       = 5;
            programs[4].ProductionYear = 2013;
            programs[4].Owner.name     = "Sasha";

            ProgramSequence seq = new ProgramSequence();

            foreach (TVProgram program in programs)
            {
                seq.addProgram(program);
            }

            Console.WriteLine($"Full program length is {seq.Duration}");
            Console.WriteLine($"The number of advertising is {seq.Ads}");
            Console.WriteLine($"Number of program with some year of production is {seq.ProdYear(2000)}");
        }
Beispiel #2
0
 public void addProgram(TVProgram program)
 {
     m_programList.Add(program);
     m_duration += program.Duration;
     if (program is Advertising)
     {
         ++m_ads;
     }
     m_production = program.ProductionYear;
 }
Beispiel #3
0
        public void removeProgram(int index)
        {
            TVProgram prog = m_programList.ElementAt(index);

            m_duration -= prog.Duration;
            if (prog is Advertising)
            {
                --m_ads;
            }
            m_programList.RemoveAt(index);
        }
Beispiel #4
0
        public bool Equals(object obj)
        {
            TVProgram tmp = obj as TVProgram;

            if (tmp != null)
            {
                if (this.Author == tmp.Author && this.ContainsAds == tmp.ContainsAds && this.Duration == tmp.Duration)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            throw new Exception("Невозможно преобразовать объект к типу TVprogram.");
        }
Beispiel #5
0
 public void addProgram(TVProgram program)
 {
     Debug.Assert(program != null);
     m_programList.Add(program);
     m_duration += program.Duration;
     if (m_duration >= 24 * 3600)
     {
         throw new InvalidDurationException();
     }
     if (program is Advertising)
     {
         ++m_ads;
     }
     else if (!(program is TVProgram))
     {
         throw new InvalidProgramException();
     }
 }
Beispiel #6
0
        static void Main(string[] args)
        {
            TVProgram[] programs = new TVProgram[3];

            programs[0] = new Film();
            programs[1] = new Cartoon();
            programs[2] = new News();

            Triller triller = new Triller();

            triller.ShowProgram();
            ((IProgram)triller).ShowProgram();

            foreach (TVProgram program in programs)
            {
                Printer.iAmPrinting(program);
                program.ShowProgram();
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            try
            {
                TVProgram[] programs = new TVProgram[4];

                programs[0] = new Film();
                programs[1] = new Cartoon();
                programs[2] = new News();
                programs[3] = new Advertising();

                programs[0].Duration = 4;
                programs[1].Duration = 6;
                programs[2].Duration = 3;
                programs[3].Duration = 200;
                for (int k = 0; k < 4; k++)
                {
                    Debug.Assert(programs[k].Duration != 0, "Duration cannot be 0!");
                }


                ProgramSequence seq = new ProgramSequence();

                foreach (TVProgram program in programs)
                {
                    seq.addProgram(program);
                }

                Console.WriteLine($"Full program length is {seq.Duration}");
                Console.WriteLine($"The number of advertising is {seq.Ads}");
            }
            catch (InvalidProgramException e)
            {
                Console.WriteLine("Catched InvalidProgramException");
                Console.WriteLine(e.TargetSite);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.Message);
            }
            catch (InvalidDurationException e)
            {
                Console.WriteLine("Catched InvalidDurationException");
                Console.WriteLine(e.TargetSite);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.Message);
            }
            catch (EmptySequenceException e)
            {
                Console.WriteLine("Catched EmptySequenceException");
                Console.WriteLine(e.TargetSite);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.Message);
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine("Catched IndexOutOfRangeException");
                Console.WriteLine(e.TargetSite);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.Message);
            }
            catch (DivideByZeroException e)
            {
                Console.WriteLine("Catched DivideByZeroException");
                Console.WriteLine(e.TargetSite);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.TargetSite);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.Message);
            }
            finally
            {
                Console.WriteLine("Finally called");
            }
        }
Beispiel #8
0
 static public void iAmPrinting(TVProgram program)
 {
     Console.WriteLine(program.ToString());
 }