Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //Employee emp = new Employee();

            // Error! Cannot directly access private members
            // from an object!
            //emp.empName = "Marv";

            Console.WriteLine("***** Fun with Encapsulation *****\n");
            Employee emp = new Employee("Marvin", 456, 30000);

            emp.GiveBonus(1000);
            emp.DisplayStats();

            //// Use the get/set methods to interact with the object's name.
            //emp.SetName("Marv");
            //Console.WriteLine("Employee is named: {0}", emp.GetName());

            // Reset and then get the Name property.
            emp.Name = "Marv";
            Console.WriteLine("Employee is named: {0}", emp.Name);

            // Longer than 15 characters! Error will print to console.
            Employee emp2 = new Employee();

            emp2.Name = "Xena the warrior princess";
            //emp2.SetName("Xena the warrior princess");

            Employee joe = new Employee();

            joe.Age++;

            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Encapsulation *****\n");
            //Employee emp = new Employee("Marvin", 456, 30_000);
            //emp.GiveBonus(1000);
            //emp.DisplayStats();

            // Use the get/set methods to interact with the object's name.
            //emp.SetName("Marv");
            //Console.WriteLine("Employee is named: {0}", emp.GetName());

            // Reset and then get the Name property.
            //emp.Name = "Marv";
            //Console.WriteLine("Employee is named: {0}", emp.Name);

            // Longer than 15 characters! Error will print to console.
            //Employee emp2 = new Employee();
            //emp2.SetName("Xena the warrior princess");

            Employee emp = new Employee("Marvin", 45, 123, 1000, "111-11-1111", EmployeePayTypeEnum.Salaried);

            Console.WriteLine(emp.Pay);
            emp.GiveBonus(100);
            Console.WriteLine(emp.Pay);

            Console.ReadLine();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun With Encapsulation ****\n");
            Employee emp = new Employee("Marvin", 456, 30000, "123");

            emp.GiveBonus(1000);
            emp.DisplayStats();

            // Set and get the name proprety
            // It appears to the caller that it is getting and setting a public
            // point of data; however, the correct get and set block is called
            // behind the scenes to preserve encapsulation
            emp.Name = "Marv"; // 'Name' is the name of the property
            Console.WriteLine("Employee is named: {0}", emp.Name);

            Employee joe = new Employee();

            joe.Age++;

            /* Using the traditional acessor and mutator methods, the line above
             * would look something like:
             * joe.SetAge(joe.GetAge() + 1);
             */

            Console.ReadLine();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun With Encapsulation *****");
            Employee emp = new Employee("Marvin", 456, 30_000);

            emp.GiveBonus(1000);
            emp.DisplayStats();

            emp.Name = "Marv";
            Console.WriteLine($"Employee is named {emp.Name}");
            //Use the get/set methods to interact with the object.
            //emp.SetName("Marv");
            //Console.WriteLine($"Employee is named {emp.GetName()}");

            Console.ReadLine();

            Employee joe = new Employee("Joe", 35, 123, 30000);

            for (int i = 0; i < 10; i++)
            {
                joe.Age++;
                if (i % 2 == 0)
                {
                    joe.GiveBonus(5000);
                    Console.WriteLine($"{joe.Name} is {joe.Age} and just got a bonus. He now makes {joe.Pay}");
                }
            }
            Console.WriteLine($"{joe.Name} is {joe.Age} years old. He makes {joe.Pay} dollars a year");
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Encapsulation *****\n");

            // Employee emp = new Employee("Marvin",456,30_000);
            // emp.GiveBonus(1000);
            // emp.DisplayStats();
            //
            // emp.SetName("Marv");
            // Console.WriteLine("Employee is named: {0}", emp.Name);
            //
            // Employee emp2 = new Employee();
            // emp2.SetName("dffefefwefwefwefwefwefwefwefwefwefwefwefwefwefwef");

            // Employee joe = new Employee();
            // joe.Age++;
            //
            // joe.DisplayStats();

            Employee emp = new Employee("Marvin", 45, 123, 1000, "111-11-1111", EmployeePayTypeEnum.Salaried);

            Console.WriteLine(emp.Pay);
            emp.GiveBonus(100);
            Console.WriteLine(emp.Pay);

            Console.ReadLine();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Employee emp = new Employee("Marv", 23, 0, 20000, "321-abc");

            // Give the employee a bonus
            emp.GiveBonus(1000);
            emp.DisplayStats();

            Console.ReadLine();
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Encapsulation *****\n");
            Employee emp = new Employee("Marvin", 456, 30000);

            emp.GiveBonus(1000);
            emp.DisplayStats();
            emp.Name = "Marv";
            Console.WriteLine("Employee is named: {0}", emp.GetName());
            Console.ReadLine();
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Encapsulation***\n");
            Employee emp = new Employee("Marvin", 456, 30000);

            emp.GiveBonus(1000);
            emp.DisplayStats();
            // Использовать методы get/set для взаимодействия с именем обьекта
            emp.SetName("Marv");
            Console.WriteLine("Employee is named: {0}", emp.GetName());
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Encapsulation *****\n");
            Console.WriteLine("These folks work at {0}.", Employee.Company);

            Employee emp = new Employee("Marvin", 24, 456, 30000, "111-11-1111");

            emp.GiveBonus(1000);
            emp.DisplayStats();

            Console.ReadLine();
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            Employee emp = new Employee("Marvin", 456, 30000);

            emp.GiveBonus(1000);
            emp.DisplayStats();

            // Use the get/set methods to interact with the object's name.
            emp.SetName("Marv");
            Console.WriteLine("Employee is named: {0}",
                              emp.GetName());
            Console.ReadLine();
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun whith Encapsulation *****\n");
            Employee emp = new Employee("Marvin", 456, 30000);

            emp.GiveBonus(1000);
            emp.DisplayStats();

            // Установка и получение свойства Name.

            Console.WriteLine("Employee is named: {0}", emp.Name);
            Console.ReadLine();
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Encapsulation *****\n");
            Employee emp = new Employee("Marvin", 456, 30000);

            emp.GiveBonus(1000);
            emp.DisplayStats();

            // Reset and then get the Name property.
            emp.Name = "Marv";
            Console.WriteLine("Employee is named: {0}", emp.Name);
            emp.Age++;
            Console.ReadLine();
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            Console.WriteLine("***Encapsulation***");
            Employee emp = new Employee("Marvin", 18, 456, 30000, "322322");
            Employee joe = new Employee();

            joe.Age++;
            emp.GiveBonus(1000);
            emp.DisplayStats();

            emp.Name = "Marv";
            Console.WriteLine("Emp is named: {0}", emp.Name);
            Console.ReadLine();
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            //Теперь все в порядке;
            Console.WriteLine("***** Fun with Encapsulation *****\n");
            Employee emp = new Employee("Marvin", 456, 30000);

            emp.GiveBonus(1000);
            emp.DisplayStatus();

            //Использование get/set для взаимодействия с именами объектов;
            emp.SetName("Marv");
            Console.WriteLine("Employee is named: {0}", emp.GetName());
            Console.ReadKey();
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun wiht Encapsulation ****\n");

            Employee emp = new Employee("Marvin", 456, 30000);
            emp.GiveBonus(1000);
            emp.DisplayStats();

            emp.Name = "Marv";
            Console.WriteLine("Employee is named: {0}", emp.Name);

            Employee emp2 = new Employee();
            emp2.SetName("Xena the wrairre princess");

            Console.ReadLine();
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Encapsulation ***** \n");
            Employee emp = new Employee("Marvin", 456, 3000);
            emp.GiveBonus(1000);
            emp.DisplayStats();

            // Set and get the Name property.
            emp.Name = "Marv";
            Console.WriteLine("Employee is named {0}", emp.Name);

            Employee joe = new Employee();
            joe.Age++;
            Console.WriteLine("Joe's age is {0}", joe.Age);

            Console.ReadKey();
        }
Exemplo n.º 17
0
        static void Main( string[] args )
        {
            Console.WriteLine("***** Fun with Encapsulation *****\n");
            Employee emp = new Employee("Marvin", 456, 30000);
            emp.GiveBonus(1000);
            emp.DisplayStats();

            // Set and get the Name property.
            emp.Name = "Marv";
            Console.WriteLine("Employee is named: {0}", emp.Name);

            // Longer than 15 characters!  Error will print to console.
            Employee emp2 = new Employee();
            emp2.SetName("Xena the warrior princess");

            Console.ReadLine();
        }
Exemplo n.º 18
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Employee App .. ");
            Employee emp = new Employee("Marvin", 456, 30000);

            emp.GiveBonus(1000);
            emp.Name = "Marv";
            emp.DisplayStats();


            Employee emp2 = new Employee();

            emp2.SetName("Xena the warrior princess");

            Employee joe = new Employee();

            joe.Age++;
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Employee App *****\n");
            Employee employee1 = new Employee("Marvin", 456, 30000);

            employee1.GiveBonus(1000);
            employee1.DisplayStats();
            Console.WriteLine("Employee ID : " + employee1.ID);

            Employee employee2 = new Employee("Karth", 25, 22, 40000);

            employee2.DisplayStats();

            // Set and get the Name property.
            employee1.Name = "Okashi";
            Console.WriteLine("Employee1 is now named: {0}", employee1.Name);
            Console.ReadLine();
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun with Encapsulation ****\n");
            Employee emp = new Employee("Marvin", 456, 30000);

            emp.GiveBonus(1000);
            emp.DisplayStats();

            // Использовать методы get/set ждя взаимодействия с именем обьекта.
            emp.SetName("Marv");
            Console.WriteLine("Employee is named: {0} ", emp.GetName());
            Console.ReadLine();

            // Создаем joe
            Employee joe = new Employee();

            joe.Age++; // Упращенние записи "joe.setAge(joe.GetAge() + 1;"
            Console.ReadLine();
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Encapsulation *****\n");
            Employee emp = new Employee("Marvin", 456, 30000);

            emp.GiveBonus(1000);
            emp.DisplayStats();

            //  使用get/set方法来和对象的名字进行交互
            emp.Name = ("Marv");
            Console.WriteLine("Employee is named: {0}", emp.Name);
            Console.WriteLine();

            Employee emp2 = new Employee();

            emp2.Name = ("Xena the warrior princess");

            Console.ReadLine();
        }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Encapsulation *****\n");
            Employee emp = new Employee("Marvin", 456, 30000);

            emp.GiveBonus(1000);
            emp.DisplayStats();

            // Set and get the Name property.
            emp.Name = "Marv";
            Console.WriteLine("Employee is named: {0}", emp.Name);

            // Longer than 15 characters!  Error will print to console.
            Employee emp2 = new Employee();

            emp2.SetName("Xena the warrior princess");

            Console.ReadLine();
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Encapsulation *****\n");
            Employee emp = new Employee("Marvin", 4569, 30000);

            emp.Age++;
            emp.GiveBonus(1000);
            emp.DisplayStats();
            Console.WriteLine(emp.SocialSecurityNumber);

            /*
             * //Использовать методы get/set для взаимодействия с именем объекта
             * emp.SetName("Marv");
             * Console.WriteLine("Employee is named: {0}", emp.GetName());
             */
            // Установка и получение свойства Name
            emp.Name = "Marv";
            Console.WriteLine("Employee is named: {0}", emp.Name);
            Console.ReadLine();
        }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Encapsulation *****");

            Employee emp = new Employee("Marvin", 456, 30000);

            emp.GiveBonus(1000);
            emp.DisplayStats();

            //Using get/set properties
            emp.Name = "Marv";
            Console.WriteLine($"Employee is named: {emp.Name}");

            Employee emp2 = new Employee();

            emp2.Name = "Xena the warrior princess";
            Console.WriteLine($"Employee is named: {emp2.Name}");

            Console.ReadLine();
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun with encapsulation ****");
            Employee emp = new Employee("Marvin", 456, 100);

            emp.GiveBonus(30000);
            emp.DisplayStatus();
            Console.WriteLine();

            Employee jay = new Employee();

            jay.EmpAge++;
            jay.DisplayStatus();
            Console.WriteLine();

            emp.EmpName = "Marv";
            Console.WriteLine("Employee is named: {0}", emp.EmpName);
            Console.WriteLine();

            Console.ReadLine();
        }
Exemplo n.º 26
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Encapsulation *****\n");
            Console.WriteLine("These folks work at {0}", Employee.Company);

            Employee emp = new Employee("Marvin", 456, 30000);

            emp.GiveBonus(1000);
            emp.DisplayStats();

            // Use the get/set methods to interact with the object's name.
            emp.Name = "Marv";
            Console.WriteLine("Employee is named: {0}", emp.Name);

            Employee emp2 = new Employee();

            // Longer than 15 characters!  Error will print to console.
            emp2.Name = "Xena the warrior princess";

            Console.ReadLine();
        }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            Employee emp = new Employee();

            emp.Name = "Gregory";
            emp.DisplayStats();
            Console.WriteLine();
            Employee empy = new Employee("Marvin", 456, 30000);

            empy.GiveBonus(1000);
            empy.DisplayStats();
            empy.Name = "Marv";
            Console.WriteLine("After we changed the employees name it became: {0}", empy.Name);
            Employee xena = new Employee();

            // This will throw an error
            // since it's longer than 15
            // characters.
            xena.Name = "XENA THE WARRIOR PRINCESS";
            Console.ReadLine();
        }
Exemplo n.º 28
0
        private static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Encapsulation ****\n");
            var emp = new Employee("Marvin", 456, 30000, 20);

            emp.GiveBonus(1000);
            emp.DisplayStats();

            emp.Name = "Marv";
            Console.WriteLine("Employee is named: {0}", emp.GetName());

            var emp2 = new Employee();

            emp2.SetName("Xena the warrior princess");

            var joe = new Employee();

            joe.Age++;

            Console.ReadLine();
        }
Exemplo n.º 29
0
        static void Main(string[] args)
        {
            Console.WriteLine("*** Fun with Encapsulation ***");
            Employee emp = new Employee("Jake", 30, 30000);

            emp.GiveBonus(1000);
            emp.Display();

            emp.SetName("Mike");
            Console.WriteLine("Employee is named: {0}", emp.GetName());

            Employee emp2 = new Employee();

            emp2.Name = "Xena";
            Console.WriteLine("Name of Employee: {0}", emp2.Name);

            Employee joe = new Employee();

            joe.Age++;
            joe.Display();

            Console.ReadLine();
        }