Пример #1
0
        static void Main()
        {
            var pesho = new Customer("Petar", "Petrov", "Petrov", 123456789);
            var ivan  = new Customer("Ivan", "Ivanov", "Ivanov", 123456789);

            Payment[] payments =
            {
                new Payment("book",  25.5m),
                new Payment("phone", 250.89m)
            };

            foreach (var payment in payments)
            {
                pesho.AddPayment(payment);
                ivan.AddPayment(payment);
            }

            var petarCloning = (Customer)pesho.Clone();

            Console.WriteLine(pesho == ivan);
            Console.WriteLine(pesho == pesho);
            Console.WriteLine(pesho == petarCloning);

            Console.WriteLine(pesho.CompareTo(ivan));
            Console.WriteLine(pesho.CompareTo(petarCloning));

            Customer cloning = (Customer)pesho.Clone();

            pesho.Payments[0].Price   = 200;
            cloning.Payments[0].Price = 100000;

            Console.WriteLine("Pesho cloning:\n{0}", cloning.Payments[0].Price);
            Console.WriteLine("Pesho:\n{0}", pesho.Payments[0].Price);
        }
Пример #2
0
        static void Main()
        {
            Payment p1 = new Payment("Coffee", 2.53m);
            Payment p2 = new Payment("Tea", 1.41m);
            Payment p3 = new Payment("Beer", 3.78m);
            Payment p4 = new Payment("Cheese", 6.33m);
            Payment p5 = new Payment("Bread", 1.02m);

            IList<Payment> payments1 = new List<Payment> {p1, p2};
            IList<Payment> payments2 = new List<Payment> { p1, p2 };
            IList<Payment> payments3 = new List<Payment> { p2, p3, p4, p5 };
            IList<Payment> payments4 = new List<Payment> { p3, p4 };
            IList<Payment> payments5 = new List<Payment> { p4, p5 };

            Customer pesho = new Customer("Petar", "Dimitrov", "Petrov", 6005121315, "Sofia", "0888-888888",
                "pesho.abv.bg", payments1, CustomerType.Diamond);
            Customer gosho1 = new Customer("Georgi", "Mihajlov", "Georgiev", 7510124567, "Plovdiv", "0777-777777",
                "gosho.abv.bg", payments3, CustomerType.Golden);
            Customer gosho2 = new Customer("Georgi", "Mihajlov", "Georgiev", 7510124567, "Plovdiv", "0777-777777",
                "gosho.abv.bg", payments3, CustomerType.Golden);
            Customer gosho3 = new Customer("Georgi", "Mihajlov", "Georgiev", 6510124567, "Plovdiv", "0777-777777",
                "gosho.abv.bg", payments3, CustomerType.Golden);
            Customer misho = new Customer("Mihail", "Todorov", "Todorov", 5512024567, "Ruse", "0666-666666",
                "email.abv.bg", payments4, CustomerType.OneTime);

            IList<Customer> customers = new List<Customer>
            {
                pesho, gosho1, gosho2, gosho3, misho
            };

            Console.WriteLine("Print HashCodes:");
            foreach (var customer in customers)
            {
                Console.WriteLine(customer.GetHashCode());
            }
            Console.WriteLine();

            Console.WriteLine("Print equalities: ");
            Console.WriteLine(pesho.Equals(gosho1));
            Console.WriteLine(pesho == gosho1);
            Console.WriteLine(gosho1 == gosho2);
            Console.WriteLine(gosho1 != gosho3);
            Console.WriteLine();

            Console.WriteLine("Prnt cloning:");
            Customer cloning = (Customer)pesho.Clone();
            Console.WriteLine("cloning == pesho? {0}", cloning == pesho);
            Console.WriteLine("Cloning:\n" + cloning);
            Console.WriteLine("Pesho:\n" + pesho);
            cloning.FirstName = "Joro";
            Console.WriteLine("Cloning after changing first name:\n" + cloning);
            Console.WriteLine("Pesho:\n" + pesho);

            Console.WriteLine("Compare to:");
            Console.WriteLine("gosho1 compareTo gosho2: {0}", gosho1.CompareTo(gosho2));
            Console.WriteLine("gosho1 compareTo gosho3: {0}", gosho1.CompareTo(gosho3));
            Console.WriteLine("gosho3 compareTo gosho1: {0}", gosho3.CompareTo(gosho1));
        }
Пример #3
0
        static void Main(string[] args)
        {
            Customer baiIvan = new Customer("Ivan", "Vylkov", "Goshev", "8503285842", "Planet Earth", "+359987654321",
                                            "*****@*****.**",
                                            new List <Payment>()
            {
                new Payment("some product", 45.99m),
                new Payment("other some product", 55.49m)
            },
                                            CustomerType.OneTime);

            Console.WriteLine(baiIvan);

            Customer baiYordan = baiIvan.Clone() as Customer;

            if (baiIvan == baiYordan)
            {
                Console.WriteLine("baiIvan equals baiGoran");
            }
            else
            {
                Console.WriteLine("baiIvan and baiGoran not equals");
            }

            Console.WriteLine();

            Console.WriteLine("Changes baiGoran");
            baiYordan.FirstName = "Yordan";
            Console.WriteLine(baiYordan);

            Console.WriteLine();

            Console.Write("Compare baiIvan and baiGoran: ");
            if (baiIvan.CompareTo(baiYordan) == 1)
            {
                Console.WriteLine("baiYordan");
            }
            else if (baiIvan.CompareTo(baiYordan) == -1)
            {
                Console.WriteLine("baiIvan");
            }

            Console.WriteLine();

            if (baiIvan == baiYordan)
            {
                Console.WriteLine("baiIvan equals baiGoran");
            }
            else
            {
                Console.WriteLine("baiIvan and baiGoran not equals");
            }
        }
Пример #4
0
        public static void Main()
        {
            Customer pesho1 = new Customer("Peter", "Ivanov", "Petrov", "8010201020", "AAA 5", "0888 123 456", "*****@*****.**",
                new List<Payment>{new Payment("Vnoska", 150.99)}, CustomerType.OneTime);

            Customer pesho2 = (Customer) pesho1.Clone();

            Console.WriteLine(pesho1.Equals(pesho2));
            Console.WriteLine(pesho1.CompareTo(pesho2) + "\n");

            pesho2.Id = "8010201021";

            Console.WriteLine(pesho1.Equals(pesho2));
            Console.WriteLine(pesho1.CompareTo(pesho2) + "\n");
        }
Пример #5
0
        static void Main()
        {
            IList<Payment> paymentsA = new List<Payment>()
            {
                new Payment("Utilities", 123.5m),
                new Payment("Groceries", 28.60m),
            };

            IList<Payment> paymentsB = new List<Payment>()
            {
                new Payment("Chocolate", 1.9m),
                new Payment("Coca Cola", 1.3m),
                new Payment("Vodka", 2.9m),
            };

            Customer ivan = new Customer("Simo", "Georgiev", "Vulchev", "8901221233", "Sofia, 'Suha Reka', st. Botio Petkov", 
                "0876441122", "*****@*****.**", paymentsA, CustomerType.Regular);
            Customer george = new Customer("Vasko", "Minchev", "Georgiev", "7712221122", "Dupnica, 'Gorublqne', str. Lipov Rut",
                "0885707488", "*****@*****.**", paymentsB, CustomerType.Diamond);
            Customer ivanClone = (Customer)ivan.Clone();

            Console.WriteLine(ivan.ToString());
            Console.WriteLine(ivan.CompareTo(george));
            Console.WriteLine(ivan == george);
            Console.WriteLine();

            Console.WriteLine(ivanClone.ToString());
            Console.WriteLine(ivanClone.CompareTo(ivan));
            Console.WriteLine(ivanClone == ivan);
        }
Пример #6
0
        static void Main(string[] args)
        {
            Payment        first    = new Payment("Keyboard", 120);
            Payment        second   = new Payment("Mouse", 100);
            Payment        third    = new Payment("Monitor", 670);
            List <Payment> payments = new List <Payment>();

            payments.Add(first);
            payments.Add(second);
            payments.Add(third);
            Customer one  = new Customer("Petar", "Rusev", "Rusev", "8701239089", "Sofia,Diana Bad,ul.Loven Park 3", "0897123852", "*****@*****.**", payments, GetEnumDescription.GetDescription(CustomerType.Diamond, ""));
            Customer four = new Customer("Ivan", "Rusev", "Rusev", "8701230987", "Sofia,Diana Bad,ul.Loven Park 3", "0897123852", "*****@*****.**", payments, GetEnumDescription.GetDescription(CustomerType.Gold, ""));
            Customer two  = (Customer)one.Clone();

            Console.WriteLine(one.ToString());
            Console.WriteLine(two.ToString());
            foreach (Payment p in one.Payments)
            {
                Console.WriteLine(p);
            }
            foreach (Payment p in two.Payments)
            {
                Console.WriteLine(p);
            }
            Console.WriteLine(one.CompareTo(four));
        }
Пример #7
0
        static void Main()
        {
            CustomerType typeGolden  = CustomerType.Golden;
            CustomerType typeDiamond = CustomerType.Diamond;
            Payment      easyPay     = new Payment("EasyPay", 200);
            Payment      ePay        = new Payment("EPay", 400);

            Customer firstTestCustomer  = new Customer("Ivan", "Ivanov", "Draganov", "200", "Sofia", "0882222", "[email protected]", typeGolden);
            Customer secondTestCustomer = new Customer("Zenit", "Zenitov", "Krokodilov", "400", "Sofia", "555", "[email protected]", typeDiamond);

            firstTestCustomer.AddPayment(easyPay);

            Console.WriteLine(firstTestCustomer.ToString());
            Console.WriteLine(secondTestCustomer.ToString());
            Console.WriteLine(firstTestCustomer.CompareTo(secondTestCustomer));

            Customer copyOfFirst         = firstTestCustomer;
            Customer firstCustomerCloned = (Customer)firstTestCustomer.Clone();

            copyOfFirst.FirstName = "Hi";

            Console.WriteLine(copyOfFirst);
            Console.WriteLine(firstTestCustomer);
            Console.WriteLine(firstCustomerCloned);
        }
Пример #8
0
        static void Main()
        {
            IList <Payment> paymentsA = new List <Payment>()
            {
                new Payment("Utilities", 123.5m),
                new Payment("Groceries", 28.60m),
            };

            IList <Payment> paymentsB = new List <Payment>()
            {
                new Payment("Milk", 1.5m),
                new Payment("Bread", 1.1m),
                new Payment("Organge juice", 2.2m),
            };

            Customer ivan = new Customer("Ivan", "Ivanov", "Ivanov", "8910041276", "Ruse, 'Mladost', st. Vyzrajdane",
                                         "0876112435", "*****@*****.**", paymentsA, CustomerType.Regular);
            Customer george = new Customer("George", "Mikov", "Ivanov", "0010041276", "Sofia, 'Mladost', st. Vyzrajdane",
                                           "0889112090", "*****@*****.**", paymentsB, CustomerType.Diamond);
            Customer ivanClone = (Customer)ivan.Clone();

            Console.WriteLine(ivan.ToString());
            Console.WriteLine(ivan.CompareTo(george));
            Console.WriteLine(ivan == george);
            Console.WriteLine();

            Console.WriteLine(ivanClone.ToString());
            Console.WriteLine(ivanClone.CompareTo(ivan));
            Console.WriteLine(ivanClone == ivan);
        }
Пример #9
0
        static void Main()
        {
            Customer Ivan = new Customer(3, "Ivan", "Petrov", "Goshov", "Sofia, Mladost", "+359-897-687-52", "*****@*****.**", CustomerType.Golden, new List<Payment>() { new Payment("Lenovo", 533), new Payment("Samsung", 789), });
            Customer Petar = new Customer(2, "Petar", "Goshov", "Ivanov", "Sofia, Lulin", "+359-897-534-59", "*****@*****.**", CustomerType.OneTime, new List<Payment>() { new Payment("Acer", 533), new Payment("MSI", 789), });
            Customer Ivan4o = new Customer(1, "Ivan", "Petrov", "Goshov", "Sofia, Iztok", "+359-897-687-49", "*****@*****.**", CustomerType.Diamond, new List<Payment>() { new Payment("Asus", 533), new Payment("HP", 789), });
            Customer IvanCopy = (Customer)Ivan.Clone();

            Console.WriteLine(Ivan + "\n");

            Console.WriteLine(Ivan.Equals(Petar));
            Console.WriteLine(Ivan.Equals(Ivan4o));
            Console.WriteLine(Ivan.Equals(IvanCopy) + "\n");

            Console.WriteLine(Ivan.CompareTo(IvanCopy));
            Console.WriteLine(Ivan.CompareTo(Ivan4o));
        }
Пример #10
0
        static void Main()
        {
            IList<Payment> paymentsA = new List<Payment>()
            {
                new Payment("Utilities", 123.5m),
                new Payment("Groceries", 28.60m),
            };

            IList<Payment> paymentsB = new List<Payment>()
            {
                new Payment("Milk", 1.5m),
                new Payment("Bread", 1.1m),
                new Payment("Organge juice", 2.2m),
            };

            Customer ivan = new Customer("Ivan", "Ivanov", "Ivanov", "8910041276", "Ruse, 'Mladost', st. Vyzrajdane",
                "0876112435", "*****@*****.**", paymentsA, CustomerType.Regular);
            Customer george = new Customer("George", "Mikov", "Ivanov", "0010041276", "Sofia, 'Mladost', st. Vyzrajdane",
                "0889112090", "*****@*****.**", paymentsB, CustomerType.Diamond);
            Customer ivanClone = (Customer)ivan.Clone();

            Console.WriteLine(ivan.ToString());
            Console.WriteLine(ivan.CompareTo(george));
            Console.WriteLine(ivan == george);
            Console.WriteLine();

            Console.WriteLine(ivanClone.ToString());
            Console.WriteLine(ivanClone.CompareTo(ivan));
            Console.WriteLine(ivanClone == ivan);
        }
Пример #11
0
        static void Main()
        {
            Customer pesho = new Customer("Pesho", "Peshev", "Peshliyski", 8012213456, "Peshovitza 5", "02/3456789", "*****@*****.**", new List<Payment>(), CustomerType.Regular);
            pesho.Payments.Add(new Payment("Vinkel", 100));
            pesho.Payments.Add(new Payment("Armatura", 150));
            Console.WriteLine(pesho);
            Console.WriteLine("Payments:");
            foreach (Payment item in pesho.Payments)
            {
                Console.WriteLine("- {0} - {1} BGN", item.ProductName, item.Price);
            }
            Console.WriteLine(new string('=', 30));

            Customer gosho = pesho.Clone() as Customer;
            gosho.FirstName = "Gosho";
            gosho.ID = 7704024567;
            gosho.Email = "*****@*****.**";
            gosho.Payments.Add(new Payment("Ankeri", 100));

            Console.WriteLine(gosho);
            Console.WriteLine("Payments:");
            foreach (Payment item in gosho.Payments)
            {
                Console.WriteLine("- {0} - {1} BGN", item.ProductName, item.Price);
            }
            Console.WriteLine(new string('=', 30));

            if (pesho.CompareTo(gosho) > 0)
            {
                Console.WriteLine("Customer is first, compared to the given criteria.");
            }
            else if (pesho.CompareTo(gosho) < 0)
            {
                Console.WriteLine("Customer is last, compared to the given criteria.");
            }
            else
            {
                Console.WriteLine("Customers are equal.");
            }

            Console.WriteLine("First equals second: " + pesho.Equals(gosho));
            Console.WriteLine("First == second: " + (pesho == gosho));
            Console.WriteLine("First != second: " + (pesho != gosho));

            Console.WriteLine("First's hash: " + pesho.GetHashCode());
            Console.WriteLine("Second's hash: " + gosho.GetHashCode());
        }
Пример #12
0
        static void Main(string[] args)
        {
            Payments paymentPc    = new Payments("PC", 1899);
            Payments paymentOven  = new Payments("Oven", 1111);
            Payments paymentBills = new Payments("Bills", 350);
            var      payments     = new List <Payments>()
            {
                paymentPc, paymentOven, paymentBills
            };

            Customer ivan = new Customer("Ivan",
                                         "Geshov",
                                         "Popov",
                                         8901034546,
                                         "1000 Sofia, str.Vasil Levski 78",
                                         0888223344,
                                         "*****@*****.**",
                                         payments,
                                         customType.Regular);

            Customer pesho = new Customer("Pesho",
                                          "Dobrev",
                                          "Volev",
                                          8309034116,
                                          "Kaspichan, str.Hristo Botev 33",
                                          0888777777,
                                          "*****@*****.**",
                                          payments,
                                          customType.Diamond);

            Customer cloning = ivan.Clone();

            Console.WriteLine("{0}\n", ivan.ToString());

            Console.WriteLine("\tCompare Customer Ivan with his deep clone \n" +
                              "Ivan == cloning : {0}\n", ivan.CompareTo(cloning) == 0 ? "True" : "False");

            Console.WriteLine("{0}\n", pesho.ToString());

            Console.WriteLine("\tCompare Customer Ivan with Pesho \n" +
                              "Ivan == Pesho : {0}\n", ivan.CompareTo(pesho) == 0 ? "True" : "False");
        }
Пример #13
0
        static void Main()
        {
            var pesho  = new Customer("Petar", "Ivanov", "Mitrev", 123456789);
            var pesho2 = new Customer("Petar", "Ivanov", "Mitrev", 123456788);
            var gosho  = new Customer("Gosho", "Ivanov", "Shopov", 100000001);

            Payment[] payments =
            {
                new Payment("book",     25.5m),
                new Payment("phone",  250.89m),
                new Payment("tablet",     500),
                new Payment("phone",  250.89m),
                new Payment("tablet", 500)
            };

            foreach (var payment in payments)
            {
                pesho.AddPayment(payment);
                gosho.AddPayment(payment);
            }

            var petarCloning = (Customer)pesho.Clone();

            Console.WriteLine(pesho == gosho);
            Console.WriteLine(pesho == pesho);
            Console.WriteLine(pesho == petarCloning);

            Console.WriteLine(pesho.CompareTo(gosho));
            Console.WriteLine(pesho2.CompareTo(pesho));
            Console.WriteLine(pesho.CompareTo(petarCloning));

            Console.WriteLine("=------------------------------------------");

            Customer cloning = (Customer)pesho.Clone();

            pesho.Payments[0].Price   = 200;
            cloning.Payments[0].Price = 100000;

            Console.WriteLine("Pesho cloninig:\n{0}", cloning.Payments[0].Price);
            Console.WriteLine("Pesho:\n{0}", pesho.Payments[0].Price);
        }
Пример #14
0
        static void Main()
        {
            var pesho = new Customer("Petar", "Ivanov", "Mitrev", 123456789);
            var pesho2 = new Customer("Petar", "Ivanov", "Mitrev", 123456788);
            var gosho = new Customer("Gosho", "Ivanov", "Shopov", 100000001);

            Payment[] payments =
            {
                new Payment("book", 25.5m),
                new Payment("phone", 250.89m),
                new Payment("tablet", 500),
                new Payment("phone", 250.89m),
                new Payment("tablet", 500)
            };

            foreach (var payment in payments)
            {
                pesho.AddPayment(payment);
                gosho.AddPayment(payment);
            }

            var petarCloning = (Customer)pesho.Clone();

            Console.WriteLine(pesho == gosho);
            Console.WriteLine(pesho == pesho);
            Console.WriteLine(pesho == petarCloning);

            Console.WriteLine(pesho.CompareTo(gosho));
            Console.WriteLine(pesho2.CompareTo(pesho));
            Console.WriteLine(pesho.CompareTo(petarCloning));

            Console.WriteLine("=------------------------------------------");

            Customer cloning = (Customer)pesho.Clone();

            pesho.Payments[0].Price = 200;
            cloning.Payments[0].Price = 100000;

            Console.WriteLine("Pesho cloninig:\n{0}", cloning.Payments[0].Price);
            Console.WriteLine("Pesho:\n{0}", pesho.Payments[0].Price);
        }
Пример #15
0
        static void Main(string[] args)
        {
            Payments paymentPc = new Payments("PC", 1899);
            Payments paymentOven = new Payments("Oven", 1111);
            Payments paymentBills = new Payments("Bills", 350);
            var payments = new List<Payments>() { paymentPc, paymentOven, paymentBills };

            Customer ivan = new Customer("Ivan",
                "Geshov",
                "Popov",
                8901034546,
                "1000 Sofia, str.Vasil Levski 78",
                0888223344,
                "*****@*****.**",
                payments,
                customType.Regular);

            Customer pesho = new Customer("Pesho",
               "Dobrev",
               "Volev",
               8309034116,
               "Kaspichan, str.Hristo Botev 33",
               0888777777,
               "*****@*****.**",
               payments,
               customType.Diamond);

            Customer cloning = ivan.Clone();

            Console.WriteLine("{0}\n", ivan.ToString());

            Console.WriteLine("\tCompare Customer Ivan with his deep clone \n" +
                "Ivan == cloning : {0}\n", ivan.CompareTo(cloning) == 0 ? "True" : "False");

            Console.WriteLine("{0}\n", pesho.ToString());

            Console.WriteLine("\tCompare Customer Ivan with Pesho \n" +
               "Ivan == Pesho : {0}\n", ivan.CompareTo(pesho) == 0 ? "True" : "False");
        }
Пример #16
0
        public static void Main()
        {
            try
            {
                Customer stefan = new Customer("Stefan", "Ivanov", "Stefanov", "1234567890", "Sofia", "+359888777666", "*****@*****.**", new Payment("VGA", 260.0m), CustomerType.Diamond);

                Customer copyOfStefan = stefan;

                Customer ivan = stefan.Clone() as Customer;
                ivan.FirstName = "Ivan";
                ivan.AddPayment(new Payment("CPU", 354.12m));
                
                Console.WriteLine(stefan);
                Console.WriteLine("Deep copy:\n{0}", ivan);
                Console.WriteLine("Equals (different customers): {0}", stefan.Equals(ivan));
                Console.WriteLine("Compare (different customers): {0}", stefan.CompareTo(ivan));
                Console.WriteLine("Equals (different customers, same reference): {0}", stefan.Equals(copyOfStefan));
                Console.WriteLine("Compare (different customers, same reference): {0}", stefan.CompareTo(copyOfStefan));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        } 
Пример #17
0
        internal static void Main()
        {
            Customer thomas = new Customer("Thomas", "Anderson", "Rodriguez", "123456798", "America", "+1123456789", "*****@*****.**", new List<Payment>() { new Payment("Jacket", 99.99m), new Payment("Jeans", 49.99m) }, CustomerType.Diamond);

            Console.WriteLine("ToString()");          
            Console.WriteLine(thomas);

            Console.WriteLine("Clone()"); 
            Customer copy = thomas.Clone() as Customer;
            Console.WriteLine(copy);

            Console.WriteLine("Is copy deep?");
            copy.FirstName = "Lee";
            copy.Payments = new List<Payment>()
            {
                new Payment("Shoes", 29.99m)
            };
            copy.Id = "123456798";
            Console.WriteLine(copy);
            Console.WriteLine(thomas);

            Console.WriteLine("Equals()"); 
            Console.WriteLine(thomas.Equals(copy));
            Customer third = thomas.Clone() as Customer;
            Console.WriteLine(thomas.Equals(third));

            Console.WriteLine("== and !=");
            Console.WriteLine(thomas == copy);
            Console.WriteLine(thomas != copy);
            Console.WriteLine(thomas == third);
            Console.WriteLine(thomas != third);

            Console.WriteLine("CompareTo()"); 
            Console.WriteLine(thomas.CompareTo(copy));
            Console.WriteLine(thomas.CompareTo(third));
        }
Пример #18
0
 static void Main(string[] args)
 {
     Payment first=new Payment("Keyboard",120);
     Payment second=new Payment("Mouse",100);
     Payment third=new Payment("Monitor",670);
     List<Payment>payments=new List<Payment>();
     payments.Add(first);
     payments.Add(second);
     payments.Add(third);
     Customer one = new Customer("Petar", "Rusev", "Rusev", "8701239089", "Sofia,Diana Bad,ul.Loven Park 3", "0897123852", "*****@*****.**",payments,GetEnumDescription.GetDescription(CustomerType.Diamond,""));
     Customer four = new Customer("Ivan", "Rusev", "Rusev", "8701230987", "Sofia,Diana Bad,ul.Loven Park 3", "0897123852", "*****@*****.**", payments, GetEnumDescription.GetDescription(CustomerType.Gold, ""));
     Customer two = (Customer)one.Clone();
     Console.WriteLine(one.ToString());
     Console.WriteLine(two.ToString());
     foreach(Payment p in one.Payments)
     {
         Console.WriteLine(p);
     }
     foreach (Payment p in two.Payments)
     {
         Console.WriteLine(p);
     }
     Console.WriteLine(one.CompareTo(four));
 }