Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Примерен вход
- 3
- Bear, 2, 200, Sofia
- Machka, 1, 2, Mihailovgrad
- Koza, 4, 30, Berkovica
- exit -> exit
- 3 -> Броя на животни за попълване
- Формат на попълване: Тип на животно, години, тегло, местоположение.
- * СЪС ЗАПЕТАЯ И ИНТЕРВАЛ!
- След това може да напишеш тип животно и ще ти принтира информация за този тип.
- За да се излезе от програмата, напиши Exit.
- */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.SqlServer.Server;
- namespace TestSharp
- {
- class Program
- {
- static void Main(string[] args)
- {
- const string bear = "Bear";
- var wildLife = new Dictionary<string, List<Animal>> { [bear] = new List<Animal>() };
- Console.WriteLine("Please enter the number of animals you are about to enter");
- var numOfEntries = int.Parse(Console.ReadLine());
- for (int i = 0; i < numOfEntries; i++)
- {
- Console.WriteLine("Enter animal in the following format: Animal Type, Age, Wight, Location");
- var input = Console.ReadLine().Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- var type = input[0];
- var age = int.Parse(input[1]);
- var weight = double.Parse(input[2]);
- var location = input[3];
- var animal = new Animal(type, age, weight, location);
- if (!wildLife.ContainsKey(type)) wildLife[type] = new List<Animal>();
- wildLife[type].Add(animal);
- }
- Console.WriteLine("Data was populated!" + Environment.NewLine);
- Console.WriteLine($"The number of animals of type Bear: {wildLife["Bear"].Count}");
- while (true)
- {
- Console.WriteLine("Enter the type of animal or type exit to exit.");
- var input = Console.ReadLine();
- if (input == "exit") break;
- if (wildLife.ContainsKey(input))
- wildLife[input].ForEach(Console.WriteLine);
- else
- Console.WriteLine("Invalid animal type!");
- }
- }
- }
- class Animal
- {
- public string AnimalType { get; set; }
- public int Age { get; set; }
- public double Weight { get; set; }
- public string Location { get; set; }
- public Animal(string type, int age, double weight, string location)
- {
- this.AnimalType = type;
- this.Age = age;
- this.Weight = weight;
- this.Location = location;
- }
- public override string ToString()
- {
- return $"Type: {this.AnimalType}, Age: {this.Age}, Weight: {this.Weight}, Location: {this.Location}";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement