Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");
            SalesPerson danny = new SalesPerson();

            danny.Name        = "Danny";
            danny.Age         = 31;
            danny.SalesNumber = 50;

            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);

            //错误!不能从对象实例中直接访问受保护数据
            //Employee emp = new Employee();
            //emp.empName = "Fred";

            double cost = chucky.GetBenefitCost();

            //  定义福利等级
            Employee.BenefitPackage.BenefitPackageLevel myBendfitLevel = Employee.BenefitPackage.BenefitPackageLevel.Platinum;

            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();
            Console.WriteLine();

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        // Create a subclass object and access base class functionality
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");
            SalesPerson fred = new SalesPerson();
            fred.Age = 31;
            fred.Name = "Fred";
            fred.SalesNumber = 50;

            // Assume Manager has a constructor matching this signature:
            // (string fullName, int age, int empID,
            // float currPay, string ssn, int numbofOpts)
            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);
            double cost = chucky.GetBenefitCost();
            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            // Define my benefit level.
            BenefitPackage.BenefitPackageLevel myBenefitLevel = BenefitPackage.BenefitPackageLevel.Platinum;

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);
            fran.GiveBonus(200);
            fran.DisplayStats();

            Console.ReadKey();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");
            SalesPerson fred = new SalesPerson
            {
                Age         = 31,
                Name        = "Fred",
                SalesNumber = 50
            };

            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);

            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();
            Console.WriteLine();

            double cost = chucky.GetBenefitCost();

            Console.WriteLine($"Benefit Cost: {cost}");

            Employee.BenefitPackage.BenefitPackageLevel myBenefitLevel =
                Employee.BenefitPackage.BenefitPackageLevel.Platinum;

            CastingExamples();
            Console.ReadLine();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("=> Basic Inheritance");

            //Car myCar = new Car(80) {Speed = 50};
            //Console.WriteLine("My car is going {0}MPH", myCar.Speed);

            //MiniVan myVan = new MiniVan() { Speed = 10 };
            //Console.WriteLine("My van is going {0}MPH", myVan.Speed);

            Console.WriteLine("***** The Employee Class Hierarchy *****\n");
            SalesPerson fred = new SalesPerson()
            {
                Age = 31, Name = "Fred", SalesNumber = 50
            };

            fred.DisplayStats();

            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);

            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");
            SalesPerson fred = new SalesPerson();

            fred.Age         = 31;
            fred.Name        = "Fred";
            fred.SalesNumber = 50;
            Console.ReadLine();

            // Assume Manager has a constructor matching this signature:
            // (string fullName, int age, int empID,
            // float currPay, string ssn, int numbOfOpts)
            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);

            //double cost = chucky.GetBenefitCost();
            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();
            Console.ReadLine();


            // Define benefit level
            Employee.BenefitPackage.BenefitPackageLevel mybenefitLevel =
                Employee.BenefitPackage.BenefitPackageLevel.Platinum;
            Console.ReadLine();
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");
            SalesPerson danny = new SalesPerson();
            danny.Age = 31;
            danny.Name = "Danny";
            danny.SalesNumber = 50;

            Manager chucky = new Manager("Chucky", 50, 92, 100000, "222-33-1223", 9000);
            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();
            double cost = chucky.GetBenefitsCost();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-33-1243", 31);
            fran.GiveBonus(200);
            fran.DisplayStats();

            Employee.BenefitPackage.BenefitPackageLevel myBenefitLevel =
                    Employee.BenefitPackage.BenefitPackageLevel.Platinum;

            CastingExamples();

            Console.ReadLine();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");
            SalesPerson beedle = new SalesPerson();

            beedle.Age         = 28;
            beedle.Name        = "Beedle";
            beedle.SalesNumber = 38;

            // A better bonus system!
            Manager ganondorf = new Manager("Ganondorf", 200, 4, 181000, "320-10-2923", 15000);
            double  cost      = ganondorf.GetBenefitCost();

            ganondorf.GiveBonus(3000);
            ganondorf.DisplayStats();
            Console.WriteLine();

            SalesPerson impa = new SalesPerson("Impa", 67, 21, 90000, "281-23-2180", 17);

            impa.GiveBonus(1000);
            impa.DisplayStats();

            // Define my benefit level.
            Employee.BenefitPackage.BenefitPackageLevel myBenefitLevel =
                Employee.BenefitPackage.BenefitPackageLevel.Platinum;

            Console.ReadLine();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");

            SalesPerson fred = new SalesPerson();

            fred.Age         = 32;
            fred.Name        = "Fred";
            fred.SalesNumber = 50;

            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2332", 9000);

            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson frank = new SalesPerson("Frank", 43, 93, 3000, "932-23-3232", 31);

            frank.GiveBonus(200);
            frank.DisplayStats();

            CastingExamples();

            //Привести объект Manager к объекту Hexagon невозможно
            //но этот код нормально скомпилируется!
            try
            {
                object  ted = new Manager();
                Hexagon hex = (Hexagon)ted;
            }
            catch (InvalidCastException ex)
            {
                Console.WriteLine($"{ex.Message}\n");
            }

            //Использование ключевого слова as для проверки совместимости приводимых типов
            object[] things = new object[5];
            things[0] = new SalesPerson();
            things[1] = false;
            things[2] = new Manager();
            things[3] = "Last thing";
            things[4] = new PTSalesPerson();

            foreach (object item in things)
            {
                Employee h = item as SalesPerson;
                if (h == null)
                {
                    Console.WriteLine($"Item is not SalesPerson");
                }
                else
                {
                    Console.WriteLine($"{item} is SalesPerson");
                }
            }

            Console.ReadLine();
        }
Ejemplo n.º 9
0
        private static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");
            var fred = new SalesPerson();

            fred.Name        = "Fred";
            fred.Age         = 45;
            fred.SalesNumber = 50;
            fred.DisplayStats();
            Console.ReadLine();
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");
            SalesPerson fred = new SalesPerson();

            fred.Age         = 31;
            fred.Name        = "Fred";
            fred.SalesNumber = 50;

            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);

            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();

            object  frank = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);
            Hexagon hex;

            try
            {
                hex = (Hexagon)frank;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            object[] things = new object[4];
            things[0] = new Hexagon();
            things[1] = false;
            things[2] = new Manager();
            things[3] = "Last thing";

            foreach (object item in things)
            {
                Hexagon h = item as Hexagon;
                if (h == null)
                {
                    Console.WriteLine("Item is not a hexagon");
                }
                else
                {
                    h.Draw();
                }
            }

            Console.ReadLine();
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            Manager     chucky = new Manager("chucky", 50, 92, 10000, "586-15-4561", 900);
            SalesPerson mike   = new SalesPerson("mike", 23, 64, 20000, "123-56-4567", 31);

            chucky.DisplayStats();
            Console.WriteLine();
            mike.DisplayStats();

            CastingExamples();
            Console.Read();
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");

            // Error! Cannot create an abstract class!
            //Employee X = new Employee();

            // A better bonus system!
            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);
            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);
            fran.GiveBonus(200);
            fran.DisplayStats();

            // ITSpecialist
            ITSpecialist itsepc = new ITSpecialist()
            {
              Age = 31,
              Education = "MSc in IT",
              ID = 45,
              Name = "Phil",
              SocialSecurityNumber = "444-33-2222",
              SpecialistKnowledge = ".NET",
              Pay = 90000,
              Benefits = new Employee.BenefitPackage()
            };
            Console.WriteLine("FedTax -> {0}", itsepc.getFedTax(90000));
            Console.WriteLine("SSTax -> {0}", itsepc.getSsTax(125, 90000));

            Console.WriteLine("\r\n");

            // Secretary
            Secretary sec = new Secretary()
            {
              Age = 23,
              Education = "Gymi",
              ID = 47,
              Name = "Susy",
              SocialSecurityNumber = "333-22-1111",
              LanguageKnowledge = "French",
              Pay = 45000,
              Benefits = new Employee.BenefitPackage()
            };
            Console.WriteLine("FedTax -> {0}", sec.getFedTax(45000));
            Console.WriteLine("HealthFee -> {0}", sec.getHealthFee(100, 45000));

            CastingExamples();

            Console.ReadLine();
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            Console.WriteLine("****** The Employee Class Hierarchy ******\n");
            SalesPerson fred = new SalesPerson()
            {
                Age = 31, Name = "Fred", SalesNumber = 50, Pay = 6000
            };
            Manager chucky = new Manager("Chucky", 45, 1497, 102450, "1678-05-04", 9000);
            double  cost   = chucky.GetBenefitCost();

            Employee.BenefitPackage.BenefitPackageLevel myBenefitlevel = Employee.BenefitPackage.BenefitPackageLevel.Platinum;
            chucky.DisplayStats();
            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();
            fred.DisplayStats();
            fred.GiveBonus(150);
            fred.DisplayStats();
            Console.WriteLine();

            CastingExamples();
            Hexagon hex;
            object  frank = new Manager();

            try
            {
                hex = (Hexagon)frank;
            }
            catch (Exception e)
            {
                ConsoleColor prevCol = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(e.Message);
                Console.ForegroundColor = prevCol;
            }

            TestAsKeyword();
            Console.ReadLine();
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            SalesPerson fred = new SalesPerson
            {
                Age         = 31,
                Name        = "Fred",
                ID          = 2,
                SalesNumber = 50
            };

            fred.DisplayStats();
            Console.ReadKey();
        }
Ejemplo n.º 15
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            SalesPerson fred = new SalesPerson("Brenda", 35, 287, 18000, "JN8276172A", 247);

            fred.Age         = 31;
            fred.Name        = "Fred";
            fred.SalesNumber = 50;

            Manager chucky = new Manager("Chucky", 50, 92, 10000, "333-23-2322", 9000);

            double cost = chucky.GetBenefitCost();

            Console.WriteLine("Benefits Cost:{0}", cost.ToString());
            Employee.BenefitsPackage.BenefitPackageLevel myBenefitLevel = Employee.BenefitsPackage.BenefitPackageLevel.Platinum;

            chucky.GiveBonus(300);
            chucky.DisplayStats();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 30000, "832-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();
            object  frank = new Manager("Frank Zappa", 9, 3000, 40000, "111-11-1111", 5);
            Hexagon hex;

            try { hex = (Hexagon)frank; }
            catch (InvalidCastException ex)
            { Console.WriteLine(ex.Message); }

            object[] things = new object[4];
            things [0] = new Hexagon();
            things [1] = false;
            things [2] = new Manager();
            things[3]  = "Last Thing";

            foreach (object item in things)
            {
                Hexagon h = item as Hexagon;
                if (h == null)
                {
                    Console.WriteLine("Item is not a Hexagon");
                }
                else
                {
                    h.Draw();
                }
            }

            CastingExamples();
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            SalesPerson danny = new SalesPerson();

            danny.Age = 31;
            danny.Name = "Danny";
            danny.SalesNumber = 50;

            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);

            chucky.GiveBonus(300);

            double cost = chucky.GetBenefitCost();

            chucky.DisplayStats();

            Console.WriteLine("Benefícios: {0}", cost);

            Employee.BenefitPackage.BenefitPackageLevel myBenefitLevel = Employee.BenefitPackage.BenefitPackageLevel.Platinum;

            Console.WriteLine("Level: {0}", myBenefitLevel);

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

            fran.GiveBonus(200);

            fran.DisplayStats();

            try
            {

                PTSalesPerson ptSales = ((PTSalesPerson)danny);
            }
            catch (InvalidCastException ex)
            {
                Console.WriteLine(ex.Message);
            }

            PTSalesPerson ptCast = danny as PTSalesPerson;

            if (ptCast == null)
            {
                Console.WriteLine("Sorry, danny is not PTSalesPerson");
            }

            Console.WriteLine(danny.ToString() + "&&" + danny.GetType());

            Console.ReadLine();
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            SalesPerson fred = new SalesPerson();

            fred.Name        = "Fred";
            fred.Age         = 31;
            fred.SalesNumber = 50;

            fred.DisplayStats();


            Employee.BenefitPackage.BenefitPackageLevel myBenefitLevel = Employee.BenefitPackage.BenefitPackageLevel.Platinum;

            Console.ReadKey();
        }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");

            //Random r = new Random();
            //Console.WriteLine(r);
            //Console.WriteLine(r.Next(500));
            //SalesPerson m = new SalesPerson();
            //Console.WriteLine();

            // A better bonus system!
            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);

            chucky.GiveBonus(300);
            Console.WriteLine(chucky);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();
            Console.WriteLine();

            ArrayObjectObjects();

            Console.WriteLine();

            // Ack! You can't cast frank to a Hexagon, but this compiles fine!
            object  frank = new Manager();
            Hexagon hex;

            try
            {
                hex = (Hexagon)frank;
            }
            catch (InvalidCastException ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine();
            CastingExamples();

            Console.ReadLine();
        }
Ejemplo n.º 19
0
        public static int Main(string[] args)
        {
            Console.WriteLine("These folks work at " + Employee.Company);
            Console.WriteLine();

            // Uncomment to test abstract base class.
            // Employee e = new Employee();

            Manager chucky = new Manager("Chucky", 92, 100000, "333-23-2322", 9000);

            chucky.GiveBonus(300);
            chucky.DisplayStats();

            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 93, 30000, "932-32-3232", 31);

            fran.GiveBonus(201);
            fran.DisplayStats();

            // Casting!

            // A Manager 'is-a' object.
            object o = new Manager("Frank Zappa", 9, 40000, "111-11-1111", 5);

            // A Manager 'is-a' Employee too.
            Employee e = new Manager("MoonUnit Zappa", 2, 20000, "101-11-1321", 1);

            // A PTSales dude(tte) is a Sales dude(tte)
            SalesPerson sp = new PTSalesPerson("Jill", 834, 100000, "111-12-1119", 90);

            FireThisPerson(e);
            FireThisPerson(sp);

            // Error!  Must cast when moving from base to derived!
            // FireThisPerson(o);
            FireThisPerson((Employee)o);

            // Numerical casts...
            int  x = 30000;
            byte b = (byte)x;   // Loss of information here…



            return(0);
        }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");

            // Create a subclass object and access base class functionality.
            SalesPerson fred = new SalesPerson();

            fred.Age         = 31;
            fred.Name        = "Fred";
            fred.SalesNumber = 50;

            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);
            double  cost   = chucky.GetBenefitCost();

            // Create and use the public inner class. OK!
            OuterClass.PublicInnerClass inner;
            inner = new OuterClass.PublicInnerClass();

            // Compiler Error! Cannot access the private class.
            //OuterClass.PrivateInnerClass inner2;
            //inner2 = new OuterClass.PrivateInnerClass();

            // Define my benefit level.
            Employee.BenefitPackage.BenefitPackageLevel myBenefitLevel = Employee.BenefitPackage.BenefitPackageLevel.Platinum;
            Console.WriteLine("BenefitPackageLevel: {0}", myBenefitLevel);
            Console.WriteLine();

            // Give each employee a bonus?
            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();
            Console.WriteLine();

            // Error! Cannot create an instance of an abstract class!
            //Employee X = new Employee();

            CastingExamples();

            Console.ReadLine();
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");

            // A better bonus system!
            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);

            chucky.GiveBonus(300);

            // use the nested class
            chucky.Benefits.benefitPackageLevel = Employee.BenefitPackage.BenefitPackageLevel.Platinum;

            // use the standalone class
            chucky.empBenefits2.benefitPackageLevel = BenefitPackage.BenefitPackageLevel.Platinum;
            chucky.DisplayStats();

            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();
            Console.WriteLine();

            ArrayOfArbitraryObjects();  // a weird test of casting
            CastingExamples();

            Console.WriteLine();

            // Ack! You can't cast frank to a Hexagon, but this compiles fine!
            object  frank = new Manager();
            Hexagon hex;

            try
            {
                hex = (Hexagon)frank;
            }
            catch (InvalidCastException ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadLine();
        }
Ejemplo n.º 22
0
        static void Main( string[] args )
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");

            // Give each employee a bonus?
            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);
            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);
            fran.GiveBonus(200);
            fran.DisplayStats();

            Console.WriteLine();
            CastingExamples();

            Console.ReadLine();
        }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** The Employee Class Hierarchy ****\n");
            SalesPerson fred = new SalesPerson();
            fred.p_empAge = 31;
            fred.p_empName = "Fred";
            fred.p_SalesNumber = 100;

            // Assume Manager has a constructor matching this signature:
            // ...
            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);
            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);
            fran.GiveBonus(200);
            fran.DisplayStats();
            Console.ReadLine();
        }
Ejemplo n.º 24
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");

            // Give each employee a bonus?
            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);

            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();

            Console.WriteLine();
            CastingExamples();

            Console.ReadLine();
        }
Ejemplo n.º 25
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");

            // Error! Cannot create an abstract class!
            //Employee X = new Employee();

            // A better bonus system!
            Manager chucky = new Manager("Chucky", 50, 92, 0, "333-23-2322", 0);
            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);
            fran.GiveBonus(200);
            fran.DisplayStats();

            CastingExamples();

            Console.ReadLine();
        }
Ejemplo n.º 26
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy ****\n");

            Manager chucky = new Manager("Cucky", 50, 92, 100000, "333-23-2322", 9000);

            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 300, "932-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();

            // A Manager "is-a" System.Object, so we can
            // store a Manager reference in an object variable just fine.
            object frank = new Manager("Frank Zappa", 9, 3000, 40000, "123", 5);

            GivePromotion((Manager)frank); // explicit casting, yay!

            //A Manager "is-an" Employee too
            Employee moonUnit = new Manager("MoonUnit Zappa", 2, 3001, 20000, "567", 1);

            GivePromotion(moonUnit);

            // A PTSalesPerson "is-a" SalesPerson
            SalesPerson jill = new PTSalesPerson("Jill", 834, 30001, 123123, "123124", 90);

            GivePromotion(jill);

            // Use "as" to test compatability

            /* Hexagon hex2 = frank as Hexagon;
             * if (hex2 == null)
             *      Console.WriteLine("Sorry, frank is not a Hexagon...");
             */

            Console.ReadLine();
        }
Ejemplo n.º 27
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");

            // A better bonus system!
            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);

            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();
            Console.WriteLine();

            // Error!  Cannot create an abstract class!
            // Employee X = new Employee();
            FunWithCasting();
            Console.ReadLine();
        }
Ejemplo n.º 28
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");
            SalesPerson fred = new SalesPerson();

            fred.Age         = 31;
            fred.Name        = "Fred";
            fred.SalesNumber = 50;

            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);

            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();

            Console.ReadLine();
        }
        //  Create a subclass object and access base class functionality.
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierachy *****\n");
            SalesPerson fred = new SalesPerson();

            fred.Age         = 31;
            fred.Name        = "Fred";
            fred.SalesNumber = 50;

            //Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);
            //chucky.GiveBonus(300);
            //double cost = chucky.GetBenefitCost();
            //chucky.DisplayStats();
            //Console.WriteLine();

            //SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);
            //fran.GiveBonus(200);
            //fran.DisplayStats();
            //Console.WriteLine();

            //  Define my benefit level.
            Employee.BenefitPackage.BenefitPackageLevel myBenefitLevel = Employee.BenefitPackage.BenefitPackageLevel.Platinum;
            Console.WriteLine("My Benefit Level is {0}", myBenefitLevel);
            Console.WriteLine();

            //  A better bonus system!
            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);

            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();
            Console.WriteLine();
        }
Ejemplo n.º 30
0
        public static void Main(string[] args)
        {
            SalesPerson fred = new SalesPerson
            {
                Age         = 31,
                Name        = "Fred",
                SalesNumber = 50
            };

            // extending PtSalesPerson from SalesPerson

            PtSalesPerson partTime1 = new PtSalesPerson
            {
                Name        = "Hari",
                Age         = 31,
                Id          = 2342,
                SalesNumber = 40,
                Pay         = 234.4F,
            };


            //Manager
            Manager chucky = new Manager("Chucky", 50, 92, 1000000, "333-2332-s23", 9000);
            double  cost   = chucky.GetBefitCost();

            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson frank = new SalesPerson("Fran", 43, 93, 3000, "9333-32-3232", 31);

            frank.GiveBonus(200);
            frank.DisplayStats();
            Console.WriteLine();

            CastingExamples();
        }
Ejemplo n.º 31
0
        static void Main(string[] args)
        {
            //коментар
            //коментар2
            //Practice makes perfect
            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333 - 32 - 3332", 9000);

            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();
            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932 - 22 - 6538", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();
            //Employee employee = new Employee(); - abstract class bans this action
            Console.WriteLine();

            object[] things = new object[4];
            things[0] = new Hexagon();
            things[1] = 3.4;
            things[2] = new Manager();
            things[3] = "Last thing";
            foreach (object ob in things)
            {
                Hexagon h = ob as Hexagon;
                if (h == null)
                {
                    Console.WriteLine("Item is not a Hexagon");
                }
                else
                {
                    h.Draw();
                }
            }
            GivePromoution(chucky);
            Console.ReadKey();
        }
Ejemplo n.º 32
0
        static void Main(string[] args)
        {
            SalesPerson fred = new SalesPerson();
            fred.Age = 31;
            fred.Name = "Fred";
            fred.SalesNumber = 50;

            Manager chucky = new Manager("Chucky", 50, 92, 100000, "3-33-11", 9000);
            double cost = chucky.GetBenefitsCost();
            

            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "3-22-22", 31);
            fran.GiveBonus(200);
            fran.DisplayStats();

            OuterClass.PublicInnerClass inner = new OuterClass.PublicInnerClass(); //OK

            //Employee e = new Employee(); ERROR, abstract class
            Console.ReadLine();
        }
Ejemplo n.º 33
0
        static void Main(string[] args)
        {
            #region Uncomment to test abstract base class.
            // Employee e = new Employee();

            // Uncomment to test readonly field.
            // Employee brenner = new Employee();
            // brenner.SSNField = "666-66-6666";
            #endregion

            Console.WriteLine("***** These folks work at {0} *****",
                              Employee.Company);

            Manager chucky = new Manager("Chucky", 35, 92, 100000, "333-23-2322", 9000);
            chucky.GiveBonus(300);
            chucky.DisplayStats();
            chucky.Age++;   // Happy birthday Chuck!
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 26, 93, 30000, "932-32-3232", 31);
            fran.GiveBonus(200);
            fran.DisplayStats();
            Console.WriteLine();

            #region Casting examples
            Console.WriteLine("***** Casting examples *****");
            // A Manager 'is-a' object.
            object frank = new Manager("Frank Zappa", 50, 9, 40000, "111-11-1111", 5);

            // A Manager 'is-a' Employee too.
            Employee moonUnit = new Manager("MoonUnit Zappa", 16, 2, 20000, "101-11-1321", 1);

            // A PTSales dude(tte) is a Sales dude(tte)
            SalesPerson jill = new PTSalesPerson("Jill", 30, 834, 100000, "111-12-1119", 90);

            // Cast from the generic System.Object into a strongly
            // typed Manager.
            Console.WriteLine("***** Counting frank's stock options *****");
            Manager mgr = (Manager)frank;
            Console.WriteLine("Frank's options: {0}", mgr.NumbOpts);
            Console.WriteLine("Frank's options: {0}",
                              ((Manager)frank).NumbOpts);

            Console.WriteLine("\n***** Firing employees using casting operations! *****");
            TheMachine.FireThisPerson(moonUnit);
            Console.WriteLine();
            TheMachine.FireThisPerson(jill);
            Console.WriteLine();

            // Error!  Must cast when moving from base to derived!
            // TheMachine.FireThisPerson(frank);

            TheMachine.FireThisPerson((Employee)frank);
            Console.WriteLine();

            #endregion

            // Creating a (very) nested BenefitPackageLevel enum variable.
            Employee.BenefitPackage.BenefitPackageLevel myBenifitLevel =
                Employee.BenefitPackage.BenefitPackageLevel.Platinum;

            Console.ReadLine();
        }
Ejemplo n.º 34
0
        static void Main(string[] args)
        {
            // create a subclass object and access base class functionality
            Console.WriteLine("***** This Employee class Hierarchy *****\n");
            SalesPerson fred = new SalesPerson
            {
                Age         = 31,
                Name        = "Fred",
                SalesNumber = 50
            };

            // Nested Type Definitions
            // Create and use the public inner class
            // example: Employee.BenefitPackage.BenefitPackageLevel.Platinum;

            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);
            double  cost   = chucky.GetBenefitCost(); // calling the BenefitPackage, a class instance within the employee class with its own property

            PTSalesPerson pauly = new PTSalesPerson("Paul", 22, 298, 28_000, "444-99-4990", 1, "Fred");

            // "Paul", 22, 298, 28_000, "444-99-4990", 1, "Fred" or "Chucky"

            // display how things are going
            Console.WriteLine($"\nSalesPerson *** {fred.GetName()} ***");
            fred.DisplayStats();

            Console.WriteLine($"\nManager *** {chucky.GetName()} ***");

            chucky.DisplayStats();

            Console.WriteLine($"\nPartTime SalesPerson *** {pauly.GetName()} ***");
            pauly.DisplayStats();
            Console.Write($"{pauly.GetName()} reports to:");
            Console.Write($"{pauly.ManagerName()}\n\n");

            // give a bonus
            float bonusAmt = 2_500;

            chucky.GiveBonus(bonusAmt);
            Console.WriteLine("{0} got a bonus of {1:c}!", chucky.Name, bonusAmt);
            chucky.DisplayStats();
            Console.WriteLine();

            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();
            Console.WriteLine();

            // give a promotion or two
            GivePromotion(fran);
            GivePromotion(pauly);

            Keyword_AS_Example();

            // temporarily showing Casting Examples method()
            CastingExamples();

            // the need for an abstract class:
            // Employee emmy = new Employee("Emma", 34, 239, 47_000, "324-23-3434");
            // emmy.DisplayStats();
            // to avoid allowing instantiation of an employee with no assignment/job classification
            // MUST remove keyword abstract from the Employee Class

            // pause program executions before exit
            Console.ReadLine();
        }
Ejemplo n.º 35
0
        // Create a subclass object and access base class functionality.
        static void Main(string[] args)
        {
            Console.WriteLine("***** The Employee Class Hierarchy *****\n");
            SalesPerson fred = new SalesPerson();

            fred.Age         = 31;
            fred.Name        = "Fred";
            fred.SalesNumber = 50;

            // Assume Manager has a constructor matching this signature:
            // (string fullName, int age, int empID, float currPay, string ssn, int numbOfOpts)
            Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);

            Console.WriteLine(chucky.Name);

            // Error! Can't access protected data from client code.
            //Employee emp = new Employee();
            //emp.empName = "Fred";

            double cost = chucky.GetBenefitCost();

            Console.WriteLine($"cost: {cost}");

            // Define my benefit level.
            Employee.BenefitPackage.BenefitPackageLevel myBenefitLevel =
                Employee.BenefitPackage.BenefitPackageLevel.Platinum;
            Console.WriteLine($"myBenefitLevel: {myBenefitLevel}");

            // Give each employee a bonus?
            // chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);
            chucky.GiveBonus(300);
            chucky.DisplayStats();
            Console.WriteLine();
            SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, "932-32-3232", 31);

            fran.GiveBonus(200);
            fran.DisplayStats();

            // Ack! You can't cast frank to a Hexagon, but this compiles fine!
            // Catch a possible runtime exception which can be happened by invalid explicit type cast.
            object  frank = new Manager();
            Hexagon hex;

            try
            {
                hex = (Hexagon)frank;
            }
            catch (InvalidCastException ex)
            {
                Console.WriteLine(ex.Message);
            }


            // Use "as" to test compatability.
            object[] things = new object[4];
            things[0] = new Hexagon();
            things[1] = false;
            things[2] = new Manager();
            things[3] = "Last thing";

            foreach (object item in things)
            {
                Hexagon h = item as Hexagon;
                if (h == null)
                {
                    Console.WriteLine("Item is not a hexagon");
                }
                else
                {
                    h.Draw();
                }
            }



            Console.ReadLine();
        }