public Food BreadSelect(Food order)
        {
            if (order.GetType() == (typeof(SevenGrainWheatBread)))
            {
                SevenGrainWheatBread sevenWheat = new SevenGrainWheatBread();
                return sevenWheat;

            }
            if (order.GetType() == (typeof(WheatBread)))
            {
                WheatBread wheat = new WheatBread();
                return wheat;
            }
            if (order.GetType() == (typeof(Italian)))
            {
                Italian italian = new Italian();
                return italian;
            }
            if (order.GetType() == (typeof(Tortilla)))
            {
                Tortilla tortilla = new Tortilla();
                return tortilla;
            }
            else
            {
                Italian italian = new Italian();
                return italian;
            }
        }
Пример #2
0
        //public class HalfTon : Truck { } // does not compile because Truck is sealed



        #endregion

        #region Inheritance & Polymorphism Pt. 1

        //static void Main()
        //{
        //    IWingedAnimal animal = new Bat();
        //    IWingedAnimal animal2 = new Bird();


        //    animal.Fly();
        //}

        //public class Person
        //{
        //    protected DateTime _dateOfBirth;

        //    public Person() { }

        //    public string Name { get; private set; }

        //    protected Person(string name)
        //    {
        //        Name = name;
        //    }

        //    public DateTime DateOfBirth
        //    {
        //        get { return _dateOfBirth; }
        //        set { _dateOfBirth = value; }
        //    }

        //}

        //public class Member : Person
        //{
        //    public Member() { }

        //    protected Member(string name) : base(name) { }

        //    public DateTime EffectiveDate { get; set; }
        //}

        //public class PolicyHolder : Member
        //{
        //    public PolicyHolder(string name, DateTime dateOfBirth)
        //    {
        //        // doesn't compile, inaccessable because _name is private to Person
        //        //_name = name;

        //        // compiles, accessable because _dateOfBirth is protected by Person so all it's child classes can access it.
        //        _dateOfBirth = dateOfBirth;
        //    }

        //    public PolicyHolder(string name) : base(name) { }


        //    public Dependent[] Dependents { get; set; }
        //}

        //public class Dependent : Member
        //{
        //    public PolicyHolder PolicyHolder { get; set; }
        //}


        //public class Animal
        //{
        //    public void Eat()
        //    {
        //        Console.WriteLine("Eating yummy food.");
        //    }
        //}

        //public interface IWingedAnimal
        //{
        //    void Fly();
        //}

        //public interface IMammal
        //{
        //    void Breath();
        //}

        //public class Bat : Animal, IWingedAnimal, IMammal
        //{
        //    public void Fly()
        //    {
        //        Console.WriteLine("Bat is flying");
        //    }

        //    public void Breath()
        //    {
        //        Console.WriteLine("Bat is breathing");
        //    }
        //}

        //public class Bird : Animal, IWingedAnimal
        //{
        //    public void Fly()
        //    {
        //        Console.WriteLine("Bird is flying");
        //    }
        //}

        #endregion

        #region Linq

        //private static readonly int[] Ints1 = { 1, 2, 3, 4, 5, 6 };
        //private static readonly int[] Ints2 = { 5, 6, 7, 8, 9, 10 };

        //static void Main()
        //{
        //    var context = new DataModel();

        //    //JoinExample(context.People, context.Claims);
        //    //CastExample(context.Cars);
        //    //ConcatExample();
        //    //UnionExample();
        //    //IntersectExample();
        //    //ExceptExample();
        //    //ContainsExample();
        //    //ZipExample();
        //    //DefaultIfEmptyExample();
        //    //DistinctExample();
        //    //FirstExample(context.People);
        //    //LastExample(context.People);
        //    //SingleExample(context.People);
        //    //GroupByExample(context);
        //    //GroupJoinExample in Mapper.cs
        //    //SelectExample(context);
        //    ComputingExample(context);


        //    Console.ReadKey(true);
        //}

        //private static void ComputingExample(DataModel context)
        //{
        //    var result1 = Ints1.Sum();
        //    var result2 = Ints1.Aggregate((x, y) => x * y);
        //    var result3 = Ints1.Average();
        //    var result4 = Ints1.Min();
        //    var result5 = context.Claims.Min(x => x.Amount);
        //    var result6 = context.Claims.Max(x => x.Amount);
        //}

        //private static void SelectExample(DataModel context)
        //{
        //    var select1 = context.People.Select(x => x.FirstName).ToList();
        //    var select2 = context.People.Select(x => x.Claims.Where(y => y.Amount > 100)).ToList();
        //    var select3 = context.People.SelectMany(x => x.Claims.Where(y => y.Amount > 100)).ToList();
        //    var select4 = context.People.Select(x => new { Name = $"{x.FirstName} {x.LastName}", ClaimsNums = x.Claims.Select(y => y.ClaimNumber) }).ToList();

        //    var select5 = (from person in context.People
        //                  where person.Claims.Count > 2
        //                  select person.FirstName).ToList();

        //    var select6 = context.People.Where(x => x.Claims.Count > 2).Select(x => x.FirstName).ToList();
        //}

        //private static void ZipExample()
        //{
        //    var result = Ints1.Zip(Ints2, (x, y) => x * y);
        //}

        //private static void UnionExample()
        //{
        //    var result = Ints1.Union(Ints2);
        //}

        //private static void SingleExample(ICollection<Person> people)
        //{
        //    people.Add(new Person { FirstName = "Steve" });

        //    //var person1 = people.Single(x => x.FirstName == "Steve");
        //    var person2 = people.SingleOrDefault(x => x.FirstName == "Matt");
        //    //var person3 = people.Single(x => x.FirstName == "Matt");
        //    var person4 = people.Single(x => x.FirstName == "Tony");
        //}


        //private static void JoinExample(ICollection<Person> people, ICollection<Claim> claims)
        //{
        //    var results = people.Join(claims, p => p.PersonId, c => c.PersonId, (p, c) => new { Person = p, Claim = c });
        //}

        //private static void IntersectExample()
        //{
        //    var result = Ints1.Intersect(Ints2);
        //}

        //private static void GroupByExample(DataModel context)
        //{
        //    var groupedclaims = context.Claims.GroupBy(x => x.Person).ToList();

        //    foreach (var groupedclaim in groupedclaims)
        //    {
        //        Console.WriteLine($"{groupedclaim.Key.FirstName} {groupedclaim.Key.LastName} Claims:");
        //        foreach (var claim in groupedclaim)
        //        {
        //            Console.WriteLine($"{claim.ClaimId} {claim.ClaimDate} {claim.Amount}");
        //        }
        //        Console.WriteLine();
        //    }
        //}

        //private static void LastExample(ICollection<Person> people)
        //{
        //    var lastPerson = people.Last();

        //    //FirstOrDefault
        //    var nullPerson = people.LastOrDefault(x => x.FirstName == "Matthew");
        //    var exceptionPerson = people.Last(x => x.FirstName == "Matthew");
        //}

        //private static void FirstExample(ICollection<Person> people)
        //{
        //    var firstPerson = people.First();

        //    //FirstOrDefault
        //    var nullPerson = people.FirstOrDefault(x => x.FirstName == "Matthew");
        //    var exceptionPerson = people.First(x => x.FirstName == "Matthew");
        //}

        //private static void ExceptExample()
        //{
        //    var result = Ints1.Except(Ints2);
        //}

        //private static void CastExample(IEnumerable<Vehicle> vehicles)
        //{
        //    var cars = vehicles.Cast<Car>();
        //}

        //private static void ConcatExample()
        //{
        //    var result = Ints1.Concat(Ints2);
        //}

        //private static void ContainsExample()
        //{
        //    var result1 = new[] { 1, 2, 3, 4, 5, 6 }.Contains(4);
        //    var result2 = "Hi my name is Steve.".Contains("Steve");
        //}

        //private static void DefaultIfEmptyExample()
        //{
        //    var list1 = new List<int>();

        //    var list2 = list1.DefaultIfEmpty();

        //    foreach (var i in list1)
        //    {
        //        Console.WriteLine(i);
        //    }

        //    Console.ReadKey(true);

        //    foreach (var i in list2)
        //    {
        //        Console.WriteLine(i);
        //    }
        //}

        //private static void DistinctExample()
        //{
        //    var list1 = new[] { 1, 2, 3, 3, 3, 4, 5, 5, 6 };
        //    var list2 = list1.Distinct();

        //    Console.WriteLine("List1:");
        //    foreach (var i in list1)
        //    {
        //        Console.WriteLine(i);
        //    }

        //    Console.WriteLine("List2:");
        //    foreach (var i in list2)
        //    {
        //        Console.WriteLine(i);
        //    }
        //}

        #endregion

        #region Access Modifiers / Misc Keywords

        //static void Main()
        //{

        //}

        //static void Main()
        //{
        //    Person person = new Person();
        //    person.Talk();
        //    person.Move();
        //    Console.WriteLine();

        //    Child child = new Child();
        //    child.Talk();
        //    child.Move();
        //    Console.WriteLine();

        //    Person person2 = new Child();
        //    person2.Talk();
        //    person2.Move();

        //    Console.ReadLine();
        //}

        //public class Person
        //{
        //    private string _name;
        //    protected DateTime _dateOfBirth;

        //    public string Name { get { return _name; } set { _name = value; } }
        //    public DateTime DateOfBirth { get { return _dateOfBirth; } set { _dateOfBirth = value; } }

        //    public void Talk()
        //    {
        //        Console.WriteLine("Person Talking");
        //    }

        //    public virtual void Move()
        //    {
        //        Console.WriteLine("Person moving");
        //    }

        //}

        //public sealed class Developer : Person
        //{
        //    public Developer()
        //    {
        //        _dateOfBirth = new DateTime();
        //        //_name = "Clint Barton";
        //    }
        //}

        //public class RyanClone : Developer
        //{
        //    public string MuscleSize { get; set; } = "Huge";
        //}

        //public class Child : Person
        //{
        //    public new void Talk()
        //    {
        //        Console.WriteLine("Child Talking");
        //    }

        //    public override void Move()
        //    {
        //        Console.WriteLine("Child Moving");
        //    }
        //}

        #endregion

        #region Extention Methods and Operators

        //public static void Main()
        //{
        //    new Person().DisplayPerson();
        //    var myPerson = new Person();
        //    myPerson.DisplayPerson();

        //    var person1 = new Person
        //    {
        //        DateOfBirth = new DateTime(1920, 7, 19)
        //    };
        //    var person2 = new Person();

        //    //- operator
        //    Console.WriteLine($"- operator: {person1 - person2}");
        //    //== operator
        //    Console.WriteLine($"== operator: {person1 == person2}");

        //    Console.ReadLine();
        //}

        #endregion

        #region C#6

        //static void Main(string[] args)
        //{
        //    //String Interpolation
        //    var hawkeye = new Person("Clint", "Barton");
        //    var fullName = hawkeye.FirstName + " " + hawkeye.LastName; //Old way
        //    var fullName2 = string.Format("{0} {1}", hawkeye.FirstName, hawkeye.LastName); //Old way
        //    var fullName3 = $"{hawkeye.FirstName} {hawkeye.LastName}"; //New way
        //    Console.WriteLine(fullName);
        //    Console.WriteLine(fullName2);
        //    Console.WriteLine(fullName3);
        //    Console.WriteLine();


        //    //Auto-Implemented Properties
        //    var captain = new Person();
        //    Console.WriteLine(captain.FirstName);
        //    Console.WriteLine(captain.LastName);
        //    Console.WriteLine(captain.Dob);
        //    Console.WriteLine();


        //    //using static
        //    WriteLine("using static example");
        //    WriteLine();


        //    //Null-Conditional Operator
        //    var ironman = new Person("Tony", "Stark");
        //    //var ironmanCity = ironman.Address.City;
        //    //var ironmanCity = ironman.Address?.City;
        //    var ironmanCity = ironman.Address?.City ?? "City not found.";
        //    Console.WriteLine(ironmanCity);
        //    Console.WriteLine();


        //    //nameof
        //    var myExampleVariable = string.Empty;
        //    Console.WriteLine(nameof(myExampleVariable));
        //    Console.WriteLine();


        //    //Exception filtering
        //    try
        //    {
        //        //throw new IndexOutOfRangeException("BadIndex");
        //        //throw new IndexOutOfRangeException();
        //        throw new ArgumentNullException();
        //    }
        //    catch (IndexOutOfRangeException ex) when (ex.Message.Equals("BadIndex"))
        //    {
        //        Console.WriteLine("Caught BadIndex");
        //    }
        //    catch (IndexOutOfRangeException)
        //    {
        //        Console.WriteLine("Caught IndexOutOfRangeException");
        //    }
        //    catch (Exception)
        //    {
        //        Console.WriteLine("Caught Exception");
        //    }
        //    Console.WriteLine();


        //    //Expression-bodied members
        //    Console.WriteLine(ironman.OldFullName);
        //    Console.WriteLine(ironman.NewFullName);

        //    Console.ReadLine();

        //}

        //class Person
        //{

        //    public string FirstName { get; } = "Steve";
        //    public string LastName { get; } = "Rogers";
        //    public string OldFullName { get { return $"{FirstName} {LastName}"; } }
        //    public string NewFullName => $"{FirstName} {LastName}";
        //    public DateTime Dob { get; set; } = new DateTime(1920, 7, 4);
        //    public Address Address { get; set; }

        //    public Person()
        //    {

        //    }

        //    public Person(string firstName, string lastName)
        //    {
        //        FirstName = firstName;
        //        LastName = lastName;
        //    }


        //}

        //public class Address
        //{
        //    public string Street { get; set; }
        //    public string City { get; set; }
        //    public string State { get; set; }
        //    public string Zip { get; set; }
        //}

        #endregion

        #region Dependency Injection

        static void Main(string[] args)
        {
            //Breads
            var ryeBread   = new RyeBread("Rainbow");
            var wheatBread = new WheatBread("Franz");

            //Meats
            var ham    = new Ham("Fresh");
            var turkey = new Turkey("Rotten");

            //Condiments
            var condiments = new List <ICondiment>
            {
                new Mayo("Hellmans"),
                new Mustard("French's"),
                new Ketchup("Heinz")
            };

            //Sandwiches
            var sandwiches = new List <Sandwich>
            {
                new Sandwich(ryeBread, ham, condiments),
                new Sandwich(wheatBread, ham, condiments),
                new Sandwich(ryeBread, turkey, condiments)
            };

            var sandwichNumber = 1;

            foreach (var sandwich in sandwiches)
            {
                Console.WriteLine($"Making sandwich {sandwichNumber++}");
                sandwich.Assemble();
                Console.WriteLine("Completed sandwich");
                Console.WriteLine();
            }


            Console.ReadKey();
        }
Пример #3
0
        public void UntitledTest()
        {
            var sandwich = new BaseSandwich();

            Assert.AreEqual(sandwich.Price, 1.00m);

            var wheatBreadSandwich = new WheatBread(sandwich);

            Assert.AreEqual(wheatBreadSandwich.Price, 2.00m);

            var hamSandwich = new Ham(wheatBreadSandwich);

            Assert.AreEqual(hamSandwich.Price, 4.00m);

            var baconHam = new Bacon(new Bacon(hamSandwich));

            Assert.IsTrue(baconHam.InnerComponent is Bacon);

            Assert.AreEqual(baconHam.Price, 5.00m);

            var discountedBaconHam = new BaconDiscount(new BaconDiscount(baconHam));

            Assert.AreEqual(discountedBaconHam.Price, 4.00m);
        }
Пример #4
0
        public void UntitledTest()
        {
            var sandwich = new BaseSandwich();

            Assert.AreEqual(sandwich.Price, 1.00m);

            var wheatBreadSandwich = new WheatBread(sandwich);

            Assert.AreEqual(wheatBreadSandwich.Price, 2.00m);

            var hamSandwich = new Ham(wheatBreadSandwich);

            Assert.AreEqual(hamSandwich.Price, 4.00m);

            var baconHam = new Bacon(new Bacon(hamSandwich));

            Assert.IsTrue(baconHam.InnerComponent is Bacon);

            Assert.AreEqual(baconHam.Price, 5.00m);

            var discountedBaconHam = new BaconDiscount(new BaconDiscount(baconHam));

            Assert.AreEqual(discountedBaconHam.Price, 4.00m);
        }
Пример #5
0
 public object FindItem(string order)
 {
     if (order == "Shredded Cheddar")
     {
         ShreddedCheddar shredChed = new ShreddedCheddar();
         return(shredChed);
     }
     else if (order == "Provolone")
     {
         Provolone prov = new Provolone();
         return(prov);
     }
     else if (order == "Cheddar Jack")
     {
         CheddarJack chedJack = new CheddarJack();
         return(chedJack);
     }
     else if (order == "Colby Jack")
     {
         ColbyJack colbyJack = new ColbyJack();
         return(colbyJack);
     }
     else if (order == "Seven Grain Wheat Bread")
     {
         SevenGrainWheatBread sevenWheat = new SevenGrainWheatBread();
         return(sevenWheat);
     }
     else if (order == "Wheat Bread")
     {
         WheatBread wheat = new WheatBread();
         return(wheat);
     }
     else if (order == "Italian")
     {
         Italian italian = new Italian();
         return(italian);
     }
     else if (order == "Tortilla")
     {
         Tortilla tortilla = new Tortilla();
         return(tortilla);
     }
     else if (order == "Coke")
     {
         Coke coke = new Coke();
         return(coke);
     }
     else if (order == "Mountain Dew")
     {
         MountainDew mtnDew = new MountainDew();
         return(mtnDew);
     }
     else if (order == "Milk")
     {
         Milk milk = new Milk();
         return(milk);
     }
     else if (order == "Orange Juice")
     {
         OrangeJuice OJ = new OrangeJuice();
         return(OJ);
     }
     else if (order == "Coffee")
     {
         Coffee coffee = new Coffee();
         return(coffee);
     }
     else if (order == "Gatorade")
     {
         Gatorade gatorade = new Gatorade();
         return(gatorade);
     }
     else if (order == "Ham")
     {
         Ham ham = new Ham();
         return(ham);
     }
     else if (order == "Turkey")
     {
         Turkey turkey = new Turkey();
         return(turkey);
     }
     else if (order == "Roast Beef")
     {
         RoastBeef beef = new RoastBeef();
         return(beef);
     }
     else if (order == "Salami")
     {
         Salami salami = new Salami();
         return(salami);
     }
     else if (order == "Bacon")
     {
         Bacon bacon = new Bacon();
         return(bacon);
     }
     else if (order == "Mayo")
     {
         Mayo mayo = new Mayo();
         return(mayo);
     }
     else if (order == "Chipotle Mayo")
     {
         ChipotleMayo chipMayo = new ChipotleMayo();
         return(chipMayo);
     }
     else if (order == "Olives")
     {
         Olives olives = new Olives();
         return(olives);
     }
     else if (order == "Lettuce")
     {
         Lettuce lettuce = new Lettuce();
         return(lettuce);
     }
     else if (order == "Spinach")
     {
         Spinach spinach = new Spinach();
         return(spinach);
     }
     else if (order == "Pickles")
     {
         Pickles pickles = new Pickles();
         return(pickles);
     }
     else
     {
         Ham ham = new Ham();
         return(ham);
     }
 }
Пример #6
0
        public object FindItem(string order)
        {
            if (order == "Shredded Cheddar")
            {
                ShreddedCheddar shredChed = new ShreddedCheddar();
                return shredChed;
            }
            else if (order == "Provolone")
            {
                Provolone prov = new Provolone();
                return prov;
            }
            else if (order == "Cheddar Jack")
            {
                CheddarJack chedJack = new CheddarJack();
                return chedJack;
            }
            else if (order == "Colby Jack")
            {
                ColbyJack colbyJack = new ColbyJack();
                return colbyJack;
            }
            else if (order == "Seven Grain Wheat Bread")
            {
                SevenGrainWheatBread sevenWheat = new SevenGrainWheatBread();
                return sevenWheat;

            }
            else if (order == "Wheat Bread")
            {
                WheatBread wheat = new WheatBread();
                return wheat;
            }
            else if (order == "Italian")
            {
                Italian italian = new Italian();
                return italian;
            }
            else if (order == "Tortilla")
            {
                Tortilla tortilla = new Tortilla();
                return tortilla;
            }
            else if (order == "Coke")
            {
                Coke coke = new Coke();
                return coke;
            }
            else if (order == "Mountain Dew")
            {
                MountainDew mtnDew = new MountainDew();
                return mtnDew;
            }
            else if (order == "Milk")
            {
                Milk milk = new Milk();
                return milk;
            }
            else if (order == "Orange Juice")
            {
                OrangeJuice OJ = new OrangeJuice();
                return OJ;
            }
            else if (order == "Coffee")
            {
                Coffee coffee = new Coffee();
                return coffee;
            }
            else if (order == "Gatorade")
            {
                Gatorade gatorade = new Gatorade();
                return gatorade;
            }
            else if (order == "Ham")
            {
                Ham ham = new Ham();
                return ham;
            }
            else if (order == "Turkey")
            {
                Turkey turkey = new Turkey();
                return turkey;
            }
            else if (order == "Roast Beef")
            {
                RoastBeef beef = new RoastBeef();
                return beef;
            }
            else if (order == "Salami")
            {
                Salami salami = new Salami();
                return salami;
            }
            else if (order == "Bacon")
            {
                Bacon bacon = new Bacon();
                return bacon;
            }
            else if (order == "Mayo")
            {
                Mayo mayo = new Mayo();
                return mayo;
            }
            else if (order == "Chipotle Mayo")
            {
                ChipotleMayo chipMayo = new ChipotleMayo();
                return chipMayo;
            }
            else if (order == "Olives")
            {
                Olives olives = new Olives();
                return olives;
            }
            else if (order == "Lettuce")
            {
                Lettuce lettuce = new Lettuce();
                return lettuce;
            }
            else if (order == "Spinach")
            {
                Spinach spinach = new Spinach();
                return spinach;
            }
            else if (order == "Pickles")
            {
                Pickles pickles = new Pickles();
                return pickles;
            }
            else
            {
                Ham ham = new Ham();
                return ham;
            }
        }
 public Sandwich(WheatBread wheat, Ham ham, Lettuce lettuce)
 {
     _wheat   = wheat;
     _ham     = ham;
     _lettuce = lettuce;
 }