Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ClassDogger
- {
- class Program
- {
- public bool running = true;
- private bool searching = true;
- private List<Dog> Dogs = new List<Dog>();
- static void Main(string[] args)
- {
- Program p = new Program();
- p.Run();
- }
- public bool Run()
- {
- Dogs.Add(new Pudel("ramus", 13, 10, 4, 10, true));
- Dogs.Add(new Labrador("kim", 14, 1, 44, 101, true));
- while (running)
- {
- inputhandler("give input:", out string input);
- if (input == "add")
- {
- add();
- }
- else if (input == "search")
- {
- search();
- }
- else if (input == "list")
- {
- doglist();
- }
- else if (input == "help")
- {
- Console.WriteLine("Valid inputs: add, search, list, exit, help");
- }
- else
- {
- Console.WriteLine("Wrong input, try again:");
- Console.Write(Environment.NewLine);
- }
- }
- return true;
- }
- #region inputhandlers
- private void inputhandler(string message, out string input)
- {
- Console.WriteLine(message);
- input = Console.ReadLine().ToLower();
- }
- private void inputhandler(string message, out int input)
- {
- Console.WriteLine(message);
- input = int.Parse(Console.ReadLine());
- }
- private void inputhandler(string message, out double input)
- {
- Console.WriteLine(message);
- input = double.Parse(Console.ReadLine());
- }
- private void inputhandler(string message, out bool input)
- {
- Console.WriteLine(message);
- input = bool.Parse(Console.ReadLine());
- }
- #endregion
- #region add
- private void add()
- {
- inputhandler("Race:", out string race);
- inputhandler("Name:", out string name);
- inputhandler("Age:", out int age);
- inputhandler("Length:", out double lenght);
- inputhandler("Withers:", out double withers);
- inputhandler("Weight:", out double weight);
- inputhandler("Sex:", out bool sex);
- if (race == "pudel")
- {
- Dogs.Add(new Pudel(name, age, lenght, withers, weight, sex));
- }
- if (race == "labrador")
- {
- Dogs.Add(new Labrador(name, age, lenght, withers, weight, sex));
- }
- if (race == "wienerdog")
- {
- Dogs.Add(new WienerDog(name, age, lenght, withers, weight, sex));
- }
- }
- #endregion
- #region list
- private void doglist()
- {
- Dogs.Sort();
- foreach (Dog Dog in Dogs)
- {
- Dog.PrintAll();
- }
- Console.ReadLine();
- }
- #endregion
- #region search
- private void search()
- {
- searching = true;
- inputhandler("Search for a dog", out string name);
- foreach (Dog Dog in Dogs)
- {
- if (Dog.Name == name)
- {
- Dog.PrintAll();
- }
- }
- while (searching)
- {
- inputhandler("What do you want to do with the dog?:", out string choice);
- #region edit
- if (choice == "edit")
- {
- foreach (Dog Dog in Dogs)
- {
- if (Dog.Name == name)
- {
- inputhandler("What do you want to change?:", out string input);
- if (input == "name")
- {
- inputhandler("What's the new name?:", out string newname);
- Dogs[Getindex(Dog)].Name = newname;
- }
- if (input == "age")
- {
- inputhandler("What's the new name?:", out int newage);
- Dogs[Getindex(Dog)].Age = newage;
- }
- if (input == "length")
- {
- inputhandler("What's the new name?:", out int newlength);
- Dogs[Getindex(Dog)].Length = newlength;
- }
- if (input == "withers")
- {
- inputhandler("What's the new name?:", out int newwithers);
- Dogs[Getindex(Dog)].Withers = newwithers;
- }
- if (input == "weight")
- {
- inputhandler("What's the new name?:", out int newweight);
- Dogs[Getindex(Dog)].Weight = newweight;
- }
- }
- }
- }
- #endregion
- #region remove
- else if (choice == "remove")
- {
- foreach (Dog Dog in Dogs)
- {
- if (Dog.Name == name)
- {
- Dogs.RemoveAt(Getindex(Dog));
- return;
- }
- }
- }
- #endregion
- #region help
- else if (choice == "help")
- {
- Console.WriteLine("Valid inputs: edit, remove, done, help");
- }
- #endregion
- else searching = false;
- }
- }
- #endregion
- #region exit
- void exit()
- {
- inputhandler("Which dog do you want to remove?:", out string input);
- if (input == "yes")
- {
- running = false;
- }
- else
- {
- return;
- }
- }
- #endregion
- #region getindex
- private int Getindex(Dog dog)
- {
- for (int i = 0; i < Dogs.Count; i++)
- {
- if (Dogs[i].Equals(dog))
- {
- return i;
- }
- }
- return -1;
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement