static void Main(string[] args) { { zoo = new Zoo(); console = ZooConsole.GetInstance(zoo); BearCage bearCage = bearCageFactory.CreateCage() as BearCage; BearFemaleCage bearFemaleCage = femaleBearCageFactory.CreateCage() as BearFemaleCage; zoo.Add(bearCage); zoo.Add(bearFemaleCage); Bear femaleBear = bearFactory.CreateAnimal(Models.Enums.MaleMode.Female) as Bear; Bear maleBear = bearFactory.CreateAnimal(Models.Enums.MaleMode.Male) as Bear; femaleBear.Name = "Female bear"; maleBear.Name = "Male bear"; femaleBear.Weight = 40; maleBear.Weight = 130; Container contForFemale = zoo.GetContainerForAnimal(femaleBear); contForFemale.Add(femaleBear); Container contForMale = zoo.GetContainerForAnimal(maleBear); contForMale.Add(maleBear); } while (true) { console.DisplayMainMenu(); } }
static void Main(string[] args) { Zoo z = new Zoo(); Aquarium aviary = new Aquarium(); Animal animal = new Animal(); z.Add(aviary); aviary.Add(animal); z.Add(animal); //aviary.Add(z); }
public ZooTest() { zoo = Lab2Zoo.Models.Factories.ZooFactory.CreateZoo(); giraffeCageFactory = new GiraffeCageFactory(); giraffeFactory = new GiraffeFactory(); bearFactory = new BearFactory(); bearCageFactory = new BearCageFactory(); giraffe = giraffeFactory.CreateAnimal() as Giraffe; bear = bearFactory.CreateAnimal() as Bear; giraffeCage = giraffeCageFactory.CreateCage() as GiraffeCage; bearCage = bearCageFactory.CreateCage() as BearCage; zoo.Add(giraffeCage); zoo.Add(bearCage); giraffeCage.Add(giraffe); bearCage.Add(bear); }
public void PrintTest() { ZooApp.Component Aviary = new Zoo("Aviary", 0); Creator cr = new BearCreator("Ben", 300); Animal animal1 = cr.Add(cr.Name, cr.Weight); Aviary.Add(animal1); string[] expected = new string[] { } string[] actual; actual = target.GetLettersOfTheAlphabet(); Assert.AreEqual(expected, actual); }
static void Main(string[] args) { var eventInterval = 5000; Console.Title = "Zoo"; Console.WriteLine("<-------- You are in the console emulator of life in a zoo. --------> "); Console.WriteLine("The zoo already has animals: by one for each available species."); Console.WriteLine("With a constant period of time (every 5 seconds) events occurs in the zoo."); _zoo = new Zoo(); var menu = new Menu(); // Animals added by default _zoo.Add("Baako", Species.Bear); _zoo.Add("Eamon", Species.Elephant); _zoo.Add("Fabio", Species.Fox); _zoo.Add("Lacey", Species.Lion); _zoo.Add("Tad", Species.Tiger); _zoo.Add("Walcott", Species.Wolf); _timer = new Timer(Event, null, 0, eventInterval); menu.MenuChoise(_zoo); Console.WriteLine("<-------- The program finished its work. --------> "); Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
public override void Execute() { NotificationService.Write("Выберете животное, которое хотите добавить:\n1 - Кошка\n2 - Собака\n3 - Курица\n4 - Аист\n5 - Тигр\n6 - Волк\n"); string choose = ReaderService.ReadLine(); //Необходима проверка на наличие команды в выборе if (_dict.ContainsKey(choose)) { Zoo.Add(_factory.GetAnimal(_dict[choose])); } else { throw new IncorrectActionException("Неверный ввод."); } }
public ContainerTest() { zoo = Lab2Zoo.Models.Factories.ZooFactory.CreateZoo(); bearCageFactory = new BearCageFactory(); bearFemaleCageFactory = new FemaleBearCageFactory(); bearMaleCageFactory = new MaleBearCageFactory(); bearFactory = new BearFactory(); giraffeFactory = new GiraffeFactory(); mainBearCage = bearCageFactory.CreateCage() as BearCage; bearFemaleCage = bearFemaleCageFactory.CreateCage() as BearFemaleCage; bearMaleCage = bearMaleCageFactory.CreateCage() as BearMaleCage; maleBear = bearFactory.CreateAnimal(Lab2Zoo.Models.Enums.MaleMode.Male) as Bear; femaleBear = bearFactory.CreateAnimal(Lab2Zoo.Models.Enums.MaleMode.Female) as Bear; giraffe = giraffeFactory.CreateAnimal(15) as Giraffe; zoo.Add(bearMaleCage); zoo.Add(mainBearCage); mainBearCage.Add(bearFemaleCage); }
public override void Execute() { NotificationService.Write("Введите путь к файлу (пустая строка означает путь по умолчанию): \n"); string text = ReaderService.ReadLine(); if (string.IsNullOrEmpty(text)) { text = "Input.txt"; } try { //Лучше использовать ?. Zoo.Add(_fileReader.Read(text)); } //Не все виды ошибок перехвачены, возможны падения программы catch (IOException) { NotificationService.Write("File or directory does not exist."); } }
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(); }
private async Task ShowAddAnimalAsync() { await ClearScreenAsync(); await Writer.WriteLineAsync("==== Add Animal ===="); await Writer.WriteLineAsync("What kind of animal do you want to add?"); await Writer.WriteLineAsync(); Type type; for (int i = 0; i < this.AnimalTypes.Length; ++i) { type = this.AnimalTypes[i]; await Writer.WriteLineAsync($"{(i + 1)} - {type.Name}"); } await Writer.WriteAsync("Enter the number of the animal you want to add and press enter: "); string choice = await Reader.ReadLineAsync(); int choiceNumber; if (string.IsNullOrWhiteSpace(choice)) { return; } else if (int.TryParse(choice, out choiceNumber)) { // user chooses values 1-number of choices, need to convert to index of array --choiceNumber; if (choiceNumber > -1 && choiceNumber < AnimalTypes.Length) { Animal a = (Animal)Activator.CreateInstance(AnimalTypes[choiceNumber]); Zoo.Add(a); await Writer.WriteLineAsync($"{AnimalTypes[choiceNumber].Name} Added!"); await Task.Delay(500); } else { await Writer.WriteAsync("Invalid Selection. Try again."); await Task.Delay(500); await ShowAddAnimalAsync(); } } else { await Writer.WriteAsync("Invalid Selection. Try again."); await Task.Delay(500); await ShowAddAnimalAsync(); } }
public void Add_WhenCageAlreadyInZoo_ReturnsArgumentException() { Assert.Throws <TypeAccessException>(() => zoo.Add(mainBearCage)); }
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); } }