private void NameMethod() { Animals b = new Birds(new Fly()); Animals m = new Mammals(new Run()); b.Run.Move(); m.Run.Move(); }
public void TestMethod16() { // Arrange Mammals mammals1 = new Mammals(); // Act Mammals mammals2 = new Mammals("Неизвестный", "Неизвестный", 1, 1000); // Assert Assert.AreEqual(mammals1, mammals2); }
private static void InheritanceExample() { var animal = new Animal(); var name = animal.Name; var AnimalTwo = new Animal("H**o Sapiens"); var mammals = new Mammals(); Console.WriteLine(mammals.Name); }
static Mammal CreateMammal(Mammals type) { switch (type) { case Mammals.cat: return(new Cat()); case Mammals.dog: return(new Dog()); } return(null); }
static void InheritanceExample() { Animals animal = new Animals(); var name = animal.Name; Console.WriteLine(name); var AnimalTwo = new Animals("H**o Sapiens"); Console.WriteLine(AnimalTwo.Name); Mammals mammals = new Mammals(); Console.WriteLine(mammals.Name); }
public void ChangeByIndexAnimal(int pos) { string s = Console.ReadLine(); if (list[pos] is Bird) { list[pos] = Bird.EnterBird(s); } if (list[pos] is PairCop) { list[pos] = PairCop.EnterPaircop(s); } if (list[pos] is Mammals) { list[pos] = Mammals.EnterMammal(s); } }
static void Main(string[] args) { Fish a = new Fish(12, "Selachii", "Gray", "male", "Hryashevie"); a.GetInfoFish(); Console.WriteLine(); Bird b = new Bird(5, "sini4ka", 7, "multiColor", "female"); b.GetInfoBird(); Console.WriteLine(); Console.WriteLine(); Mammals c = new Mammals(5, "Leon", "Orange", "Male", false); c.GetInfoMammals(); Console.WriteLine(); }
static void Main(string[] args) { // print out some statement explaining this section // separate it into a region? Console.WriteLine("====== DEMO OF USING ABSTRACT METHODS ======\n"); // create a dog object and tell it to sleep, eat, and exercise Console.WriteLine("DOG:"); Dogs dog1 = new Dogs(); Console.WriteLine(dog1.Eat()); Console.WriteLine(dog1.Sleep()); // create a mammal object and tell it to sleep, eat, and exercise Console.WriteLine("\nMAMMAL:"); Mammals mammal1 = new Mammals(); Console.WriteLine(mammal1.Eat()); Console.WriteLine(mammal1.Sleep()); Console.WriteLine("\n============================================"); }
static void Main(string[] args) { #region Primitive types Dict <string, string> myarr = new Dict <string, string>(); myarr.addElement("sinie", "first"); myarr.addElement("zakaty", "second"); myarr.addElement("kak", "third"); myarr.addElement("chernaya", "fourth"); myarr.addElement("rosa", "fifth"); myarr.CheckDictionary(); myarr.getByKey(3); Console.WriteLine("=====SORTING======"); myarr.Sort(); myarr.CheckDictionary(); #endregion #region Classes Bird b = new Bird("red", "woda", "Gragas", 15, "Wroclaw"); Bird b1 = new Bird("blue", "mushrooms", "Jax", 17, "Gdynia"); Mammals m = new Mammals("170", "80", "Katarina", 18, "Warszawa"); Mammals m1 = new Mammals("150", "80", "Warwick", 45, "Warszawa"); PairCop p = new PairCop("2", 290, "Lux", 19, "Gdansk"); PairCop p1 = new PairCop("2", 280, "Veigar", 51, "Gdansk"); PairCop p2 = new PairCop("2", 270, "Nokturn", 11, "Gdansk"); PairCop p3 = new PairCop("2", 260, "talon", 33, "Gdansk"); Dict <Animal, int> animalarr = new Dict <Animal, int>(); animalarr.addElement(b, 1); animalarr.addElement(b1, 2); animalarr.addElement(m, 3); animalarr.addElement(m1, 4); animalarr.addElement(p, 5); animalarr.addElement(p1, 6); animalarr.addElement(p2, 7); animalarr.addElement(p3, 8); animalarr.CheckDictionary(); Console.WriteLine("=====SORTING======"); animalarr.Sort(); animalarr.CheckDictionary(); #endregion Console.Read(); Console.ReadKey(); }
public static void Main() { Mammals myPet = Mammals.Cat; Colors myColor = Colors.Red; Mammals yourPet = Mammals.Dog; Colors yourColor = Colors.Red; Console.WriteLine("My favorite animal is a {0}", myPet); Console.WriteLine("Your favorite animal is a {0}", yourPet); Console.WriteLine("Do we like the same animal? {0}", myPet.Equals(yourPet) ? "Yes" : "No"); Console.WriteLine(); Console.WriteLine("My favorite color is {0}", myColor); Console.WriteLine("Your favorite color is {0}", yourColor); Console.WriteLine("Do we like the same color? {0}", myColor.Equals(yourColor) ? "Yes" : "No"); Console.WriteLine(); Console.WriteLine("The value of my color ({0}) is {1}", myColor, Enum.Format(typeof(Colors), myColor, "d")); Console.WriteLine("The value of my pet (a {0}) is {1}", myPet, Enum.Format(typeof(Mammals), myPet, "d")); Console.WriteLine("Even though they have the same value, are they equal? {0}", myColor.Equals(myPet) ? "Yes" : "No"); }
static void Main(string[] args) { Lion lion1 = new Lion(); Tiger tiger1 = new Tiger(); NewClass newClass1 = new NewClass(); Croc croc1 = new Croc(); Console.WriteLine("Croc can{0} be converted to object", (croc1 is Object)? "": "not"); Console.WriteLine("Croc can{0} be converted to ValueType", (croc1 is ValueType) ? "" : "not"); //is - проверка на конвертацию Mammals mammal1 = new Mammals(); Lion pLion = mammal1 as Lion; Console.WriteLine("Mammals to Lion conversion is {0} completed", (pLion != null) ? "" : "not"); //as - конвертация Mammals pTiger = tiger1 as Mammals; Console.WriteLine("Tiger to mammals conversion is {0} completed", (pTiger != null) ? "" : "not"); //as - конвертация Console.WriteLine(pTiger); //после переопределения ToString выводит info Console.WriteLine(lion1.ToString()); Print print1 = new Print(); Mammals[] mammalsArr = new Mammals[] { lion1, tiger1 }; foreach (var s in mammalsArr) { print1.IAmPrinting(s); Console.WriteLine(); } NewClass new1 = new NewClass(); ((IAnimal)new1).a_method(); new1.a_method(); }
static void Main(string[] args) { var myLion = new Mammals <Lion>(); }
static void Main(string[] args) { Logger logs = new Logger(); //Logger Lion lion1 = new Lion(); Tiger tiger1 = new Tiger(); NewClass newClass1 = new NewClass(); Croc croc1 = new Croc(); Parrot parrot1 = new Parrot(); parrot1.IsPredator = false; parrot1.YearOfBirth = 1993; Owl owl1 = new Owl(); owl1.IsPredator = true; owl1.YearOfBirth = 2013; Console.WriteLine("Croc can{0} be converted to object", (croc1 is Object) ? "" : "not"); Console.WriteLine("Croc can{0} be converted to ValueType", (croc1 is ValueType) ? "" : "not"); //is - проверка на конвертацию Mammals mammal1 = new Mammals(); Lion pLion = mammal1 as Lion; Console.WriteLine("Mammals to Lion conversion is {0} completed", (pLion != null) ? "" : "not"); //as - конвертация Mammals pTiger = tiger1 as Mammals; Console.WriteLine("Tiger to mammals conversion is {0} completed", (pTiger != null) ? "" : "not"); //as - конвертация Console.WriteLine(pTiger); //после переопределения ToString выводит info Console.WriteLine(lion1.ToString()); Print print1 = new Print(); Mammals[] mammalsArr = new Mammals[] { lion1, tiger1 }; foreach (var s in mammalsArr) { print1.IAmPrinting(s); Console.WriteLine(); } NewClass new1 = new NewClass(); ((IAnimal)new1).a_method(); new1.a_method(); Smth struct1; struct1.smth = "Smth"; Console.WriteLine(struct1.smth); Smth.Month month1; month1 = Smth.Month.January; Console.Write(month1 + " "); Console.WriteLine((int)month1); Zoo zoo1 = new Zoo(); tiger1.YearOfBirth = 2001; zoo1.Add(tiger1); zoo1.Add(lion1); zoo1.Add(owl1); zoo1.Add(parrot1); zoo1.ShowList(); zoo1.Remove(tiger1); ZooController yearCmp = new ZooController(); zoo1.ZooGS.Sort(yearCmp); Console.WriteLine("After sorting"); zoo1.ShowList(); /*var sortedList = from animal in zoo1.ZooGS * orderby animal.YearOfBirth descending * select animal; * * foreach(Animal animal in zoo1.ZooGS) * { * Console.WriteLine(animal); * }*/ //ADDITIONAL TASKS Console.WriteLine("Read from txt"); string path = @"/Users/elijah/БГТУ/2 Курс/ООП/Лабораторные работы/Лабораторная работа 1/C-/lab6/lab6."; try { List <Animal> collection = ZooController.ReadFile(path); foreach (Animal i in collection) { Console.WriteLine(i); } } catch (FileCannotBeFoundException e) { Console.WriteLine(e.Message); //Exception 1 logs.AddException(e); } Console.WriteLine("Read from JSON \n"); string path1 = @"/Users/elijah/БГТУ/2 Курс/ООП/Лабораторные работы/Лабораторная работа 1/C-/lab6/lab6.json"; using (StreamReader sr = new StreamReader(path1)) { string file = sr.ReadToEnd(); try { Mammals animal2 = JsonConvert.DeserializeObject <Mammals>(file); Console.WriteLine(animal2); } catch (JsonSerializationException e) { Console.WriteLine(e.Message); //Exception 2 logs.AddException(e); } } //Lab7 Tiger tiger2 = new Tiger(); Console.WriteLine("Enter tiger's age: "); try { tiger2.YearOfBirth = Convert.ToInt32(Console.ReadLine()); if (tiger2.YearOfBirth == 0) { throw new InvalidNumberException("Invalid year of birth", tiger2.YearOfBirth); } } catch (InvalidNumberException e) { Console.WriteLine(e.Message); tiger2.YearOfBirth = 2001; //Exception 3 Console.WriteLine($"Year of birth set to default: {tiger2.YearOfBirth}"); logs.AddException(e); } int[] arr = new int[5] { 1, 2, 3, 4, 5 }; Console.WriteLine("Enter the number of element: "); try { int i = Convert.ToInt32(Console.ReadLine()); if (i >= 5) { throw new IndexOutOfRangeException("Index out of range"); //Exception 4 } } catch (IndexOutOfRangeException e) { Console.WriteLine(e.Message); logs.AddException(e); } Console.WriteLine("Enter password: "******"Invalid symbol {ch} entered"); //Exception 5 } } } catch (InvalidSymbolException e) { Console.WriteLine(e.Message); logs.AddException(e); } catch { Console.WriteLine("Unhandled exceptions..."); } finally { Console.WriteLine("Program is sleeping..."); System.Threading.Thread.Sleep(1000); } Debug.Assert(true, "Program finished."); //outputs stack if the condition is false //works only in debug builds //ADDITIONAL TASK (Logger) string loggerFilePath = @"/Users/elijah/БГТУ/2 Курс/ООП/Лабораторные работы/Лабораторная работа 1/C-/lab7/lab7.txt"; logs.LogToFile(loggerFilePath); logs.LogToConsole(); }
public void Do_Mammals_have_fur() { Mammals pitbull = new Mammals(); Assert.True(pitbull.fur); }
public void Can_a_mammal_swim() { Mammals Hippo = new Mammals(); Assert.False(Hippo.Swimmer); }
public void TestAddMammal() { Mammals fox = new Mammals("Fox", "rrrrr?"); Assert.AreEqual("Live Birth", fox.birth); }
public void TestMakeMammal() { Mammals fox = new Mammals("Fox", "Hrrrr"); Assert.AreEqual(fox.birth, "Live Birth"); }
public string DoSurvey(Mammals animal) { return "Mammals Type"; }
static void Main(string[] args) { Lion lion1 = new Lion(); Tiger tiger1 = new Tiger(); NewClass newClass1 = new NewClass(); Croc croc1 = new Croc(); Parrot parrot1 = new Parrot(); parrot1.IsPredator = false; parrot1.YearOfBirth = 1993; Owl owl1 = new Owl(); owl1.IsPredator = true; owl1.YearOfBirth = 2013; Console.WriteLine("Croc can{0} be converted to object", (croc1 is Object) ? "" : "not"); Console.WriteLine("Croc can{0} be converted to ValueType", (croc1 is ValueType) ? "" : "not"); //is - проверка на конвертацию Mammals mammal1 = new Mammals(); Lion pLion = mammal1 as Lion; Console.WriteLine("Mammals to Lion conversion is {0} completed", (pLion != null) ? "" : "not"); //as - конвертация Mammals pTiger = tiger1 as Mammals; Console.WriteLine("Tiger to mammals conversion is {0} completed", (pTiger != null) ? "" : "not"); //as - конвертация Console.WriteLine(pTiger); //после переопределения ToString выводит info Console.WriteLine(lion1.ToString()); Print print1 = new Print(); Mammals[] mammalsArr = new Mammals[] { lion1, tiger1 }; foreach (var s in mammalsArr) { print1.IAmPrinting(s); Console.WriteLine(); } NewClass new1 = new NewClass(); ((IAnimal)new1).a_method(); new1.a_method(); Smth struct1; struct1.smth = "Smth"; Console.WriteLine(struct1.smth); Smth.Month month1; month1 = Smth.Month.January; Console.Write(month1 + " "); Console.WriteLine((int)month1); Zoo zoo1 = new Zoo(); tiger1.YearOfBirth = 2001; zoo1.Add(tiger1); zoo1.Add(lion1); zoo1.Add(owl1); zoo1.Add(parrot1); zoo1.ShowList(); zoo1.Remove(tiger1); ZooController yearCmp = new ZooController(); zoo1.ZooGS.Sort(yearCmp); Console.WriteLine("After sorting"); zoo1.ShowList(); /*var sortedList = from animal in zoo1.ZooGS * orderby animal.YearOfBirth descending * select animal; * * foreach(Animal animal in zoo1.ZooGS) * { * Console.WriteLine(animal); * }*/ //ADDITIONAL TASKS Console.WriteLine("Read from txt"); string path = @"/Users/elijah/БГТУ/2 Курс/ООП/Лабораторные работы/Лабораторная работа 1/C-/lab6/lab6.txt"; List <Animal> collection = ZooController.ReadFile(path); foreach (Animal i in collection) { Console.WriteLine(i); } Console.WriteLine("Read from JSON \n"); string path1 = @"/Users/elijah/БГТУ/2 Курс/ООП/Лабораторные работы/Лабораторная работа 1/C-/lab6/lab6.json"; using (StreamReader sr = new StreamReader(path1)) { string file = sr.ReadToEnd(); Mammals animal2 = JsonConvert.DeserializeObject <Mammals>(file); Console.WriteLine(animal2); } }