コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("\n************************ Abstract Class using *************************** ");
            // this is possible, but
            //THIS Person s = new Person() isn't
            //Person s = new Student();
            Student s = new Student();

            s.Name = "Marko";
            s.PrintName();
            s.PrintHeight();
            s.CalculateSomething();

            var dog1 = new Dog(Loudness.LOW);
            var dog2 = new Dog(Loudness.MEDIUM);
            var dog3 = new Dog(Loudness.HIGH);

            var cat1 = new Cat(Loudness.LOW);
            var cat2 = new Cat(Loudness.MEDIUM);
            var cat3 = new Cat(Loudness.HIGH);

            var mouse1 = new Mouse(Loudness.LOW);
            var mouse2 = new Mouse(Loudness.MEDIUM);
            var mouse3 = new Mouse(Loudness.HIGH);

            var lowSingerGroup = new SingerGroup(Loudness.LOW);

            lowSingerGroup.AddToSingerGroup(dog1);
            lowSingerGroup.AddToSingerGroup(cat1);
            lowSingerGroup.AddToSingerGroup(mouse1);

            var mediumSingerGroup = new SingerGroup(Loudness.MEDIUM);

            mediumSingerGroup.AddToSingerGroup(dog2);
            mediumSingerGroup.AddToSingerGroup(cat2);
            mediumSingerGroup.AddToSingerGroup(mouse2);

            var highSingerGroup = new SingerGroup(Loudness.HIGH);

            highSingerGroup.AddToSingerGroup(dog3);
            highSingerGroup.AddToSingerGroup(cat3);
            highSingerGroup.AddToSingerGroup(mouse3);

            //highSingerGroup.AddToSingerGroup(mouse1);

            Choir choir = new Choir(lowSingerGroup, mediumSingerGroup, highSingerGroup);

            Console.WriteLine("\n************************ Animal Choir Simulator *************************** ");
            Console.WriteLine("Press C for Crescendo or A for Arpeggio. Space for exit.");
            ConsoleKeyInfo keyinfo;

            do
            {
                keyinfo = Console.ReadKey(true);


                if (keyinfo.Key == ConsoleKey.C)
                {
                    choir.Crescendo();
                }

                if (keyinfo.Key == ConsoleKey.A)
                {
                    choir.Arpeggio();
                }
            }while (keyinfo.Key != ConsoleKey.Spacebar);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: thebored-programmer/SDF
        static void Main(string[] args)
        {
            Dog spot = new Dog();

            Console.ReadKey();
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            //			Object
            Being b=new Being();
            Console.WriteLine (b);

            //			Object attributes
            Person p1=new Person();
            p1.name="Jane";

            Person p2=new Person();
            p2.name="Beky";

            Console.WriteLine (p1.name);
            Console.WriteLine (p2.name);

            //			Methods
            Circle c=new Circle();
            c.SetRadius(5);
            Console.WriteLine (c.Area());

            //			Access modifiers
            Person2 p=new Person2();
            p.name="Jane";
            p.SetAge(17);
            Console.WriteLine ("{0} is {1} years old",p.name,p.GetAge());
            //			another example of access modifiers
            Derived d=new Derived();
            d.info();

            //			The constructor
            new Being2();
            new Being2("Tom");
            //			another example of constructor
            string name="Lenka";
            DateTime born=new DateTime(1990,3,5);

            MyFriend f=new MyFriend(name,born);
            f.info();

            //			Constructor chaining
            new Circle2(5);
            new Circle2();

            //			Class constants
            Console.WriteLine (Math.PI);
            Console.WriteLine (Math.radius);

            //			The ToString() method
            Being3 be=new Being3();
            object ob=new object();
            Console.WriteLine (ob.ToString());
            Console.WriteLine (be.ToString());
            Console.WriteLine (be);
            //			Note that when we call the Console.WriteLine() method
            //			with an object as a parameter,
            //			the ToString() is being called.

            //			Inheritance
            new Human();
            //			another example
            Console.WriteLine ();
            new Human2();
            Dog dog=new Dog();
            dog.GetCount();
            //			another example2
            Console.WriteLine ();
            Circle3 x=new Circle3(2,4,6);
            Console.WriteLine (x);

            //			Abstract classes and methods
            Console.WriteLine ();
            Circle4 z=new Circle4(12,45,22);
            Console.WriteLine (z);//show the ToString() method, defaultly
            Console.WriteLine ("Area of circle: {0}",z.Area());
            Console.WriteLine (z.GetCoordinates());
        }