By GokiSoft.com| 08:48 26/10/2021|
C Sharp

Bài tập - Chương trình quản lý Mèo C# (C Sharp) | Chương trình quản lý Cat C# (C Sharp) BT2483

Hãy xây dựng một giao diện ICat nằm trong namespace cat.exam gồm có phương thức sau:

-          public void nhap();

-          public void hienthi();

 

+ Xây dựng lớp CatDetail nằm trong namespace cat.exam  và kế thừa giao diện Cat trên rồi có thêm các thuộc tính:

-          String loai;

-          String mau (Chú ý : Màu nhập vào phải nằm trong ColorManager)

-          String noisong;

 

Cài đặt các Constructor, các phương thức set/get cho các thuộc tính của lớp và Override các phương thức trong giao diện ICat.

+ Xây dựng lớp ColorManager -> quản lý màu của Mèo đặt trong namespace cat.color

- List<string> colorList -> quản lý danh sach màu của mèo.

- nhập và hiển thị mã màu trong lớp này. 

+ Cài đặt 1 lớp ManagerCat nằm trong namespace cat.manager

- Khai báo thuộc tính catList kiểu dữ liệu là List -> được sử dụng để quản lý danh sách mèo nhập vào.

+ Cài đặt 1 lớp UsingManagerCat nằm trong namespace cat có menu chương trình sau:

           0.   Nhập danh sách mã màu

1.      Nhập thông tin của n con mèo

2.      Hiển thị thông tin

3.      Sắp xếp danh sách theo mau

4.      Tìm kiếm thông tin theo loai

5.    Sắp xếp danh sách màu theo bảng màu trong lớp ColorManager

6.      Thoát.

Nhiệm vụ:

Trong lớp UsingManagerCat phải khai báo 1 đối tượng của lớp ManagerCat và viết hàm để nhập vào thông tin của n con mèo.

Các nhiệm vụ: Hiển thị, sắp xếp, tìm kiếm thực hiện trên danh sách thông qua đối tượng của lớp ManagerCat. 

Liên kết rút gọn:

https://gokisoft.com/2483

Bình luận

avatar
Đào Mạnh Dũng [C2010L]
2021-10-15 09:58:11


#CatDetail.cs


using System;

namespace cat.exam
{
    internal class CatDetail : ICat
    {
        public string loai { get; set; }

        private string mau;

        public string noisong { get; set; }

        public string Mau
        {
            get
            {
                return mau;
            }
            set
            {
                if (UsingManagerCat.colorManager.colorList.Contains(value))
                {
                    mau = value;
                }
                else
                {
                    string color;
                    while (true)
                    {
                        Console.WriteLine("mau nhap vao khong toi tai!, nhap lai ...");
                        color = Console.ReadLine();
                        if (UsingManagerCat.colorManager.colorList.Contains(color))
                        {
                            mau = color;
                            return;
                        }
                    }
                }
            }
        }

        public CatDetail()
        {
        }

        public CatDetail(string loai, string mau, string noisong)
        {
            this.loai = loai;
            this.mau = mau;
            this.noisong = noisong;
        }

        public void hienthi()
        {
            Console.WriteLine(this);
        }

        public void nhap()
        {
            Console.Write("nhap loai : ");
            this.loai = Console.ReadLine();
            Console.Write("nhap mau : ");
            this.Mau = Console.ReadLine();
            Console.Write("nhap noisong : ");
            this.noisong = Console.ReadLine();
        }

        public override string ToString()
        {
            return "CatDetail{" + "loai=" + loai + ", mau=" + mau + ", noisong=" + noisong + '}';
        }
    }
}


#ColorManager.cs


using System.Collections.Generic;

namespace cat.color
{
    internal class ColorManager
    {
        public List<string> colorList;

        public ColorManager()
        {
            this.colorList = new List<string>();
        }

        public ColorManager(List<string> colorList)
        {
            this.colorList = colorList;
        }

        public void nhap()
        {
            System.Console.Write("nhap color : ");
            colorList.Add(System.Console.ReadLine());
        }

        public void hienthi()
        {
            foreach (var item in colorList)
            {
                System.Console.WriteLine("-- "+item);
            }
        }
    }
}


#ICat.cs


namespace cat.exam
{
    internal interface ICat
    {
        public void nhap();

        public void hienthi();
    }
}


#ManagerCat.cs


using cat.exam;
using System.Collections.Generic;

namespace cat.manager
{
    internal class ManagerCat
    {
        public List<CatDetail> catList;

        public ManagerCat()
        {
            catList = new List<CatDetail>();
        }

        public ManagerCat(List<CatDetail> catList)
        {
            this.catList = catList;
        }
    }
}


#Menu.cs


using System;

namespace lib
{
    internal delegate void SwitchCase();

    internal abstract class Menu
    {
        public static void mainMenu(SwitchCase[] menu)
        {
            int choose;
            while (true)
            {
                menu[0]();
                choose = Utility.ReadInt();
                if (choose <= menu.Length)
                {
                    menu[choose]();
                }
                else Console.WriteLine("Dau vao khong hop le! ");
            }
        }
    }
}


#UsingManagerCat.cs


using cat.color;
using cat.exam;
using cat.manager;
using lib;
using System;

namespace cat
{
    internal class UsingManagerCat : Menu
    {
        public static ColorManager colorManager = new ColorManager();
        public static ManagerCat managerCat = new ManagerCat();

        private static void Main(string[] args)
        {
            SwitchCase[] menu = { ShowMenu, InputColor, InputCat,Display,
            sort,find,sortcolor,exit};
            mainMenu(menu);
        }

        private static void sortcolor()
        {
            colorManager.colorList.Sort();
            Console.WriteLine("da sort color Manager !");
            colorManager.hienthi();
        }

        private static void exit()
        {
            Environment.Exit(0);
        }

        private static void sort()
        {
            managerCat.catList.Sort((cat1, cat2) =>
            {
                return colorManager.colorList.IndexOf(cat1.Mau) - colorManager.colorList.IndexOf(cat2.Mau);
            });
            Console.WriteLine("da sort color Manager !");
            Display();
        }

        private static void find()
        {
            Console.WriteLine("nhap loai can tim : ");
            string loai = Console.ReadLine();
            foreach (var item in managerCat.catList)
            {

                if (item.loai.Equals(loai))
                {
                    Console.WriteLine("---------");
                    item.hienthi();
                }
            }
        }

        private static void Display()
        {
            foreach (var item in managerCat.catList)
            {
                Console.WriteLine("---------");
                item.hienthi();
            }
        }

        private static void InputCat()
        {
            Console.WriteLine("nhap so meo se them : ");
            int n = Utility.ReadInt();
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine("----------");
                CatDetail catDetail = new CatDetail();
                catDetail.nhap();
                managerCat.catList.Add(catDetail);
            }
        }

        public static void InputColor()
        {
            Console.WriteLine("nhap so mau se them : ");
            int n = Utility.ReadInt();
            for (int i = 0; i < n; i++)
            {
                colorManager.nhap();
            }
        }

        public static void ShowMenu()
        {
            Console.WriteLine(
            "1.   Nhập danh sách mã màu\n" +
            "\n" +
            "2.   Nhập thông tin của n con mèo\n" +
            "\n" +
            "3.   Hiển thị thông tin\n" +
            "\n" +
            "4.   Sắp xếp danh sách theo mau\n" +
            "\n" +
            "5.   Tìm kiếm thông tin theo loai\n" +
            "\n" +
            "6.   Sắp xếp danh sách màu theo bảng màu trong lớp ColorManager\n" +
            "\n" +
            "7.   Thoát.");
        }
    }
}


#Utility.cs


using Newtonsoft.Json;
using System;
using System.IO;

namespace lib
{
    internal class Utility
    {
        public static int ReadInt()
        {
            int integer = 0;
            while (true)
            {
                try
                {
                    integer = int.Parse(Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.Write("du lieu dau vao khong hop le, nhap lai : ");
                }
            }
            return integer;
        }

        public static string ConvertDateTime(DateTime myDate)
        {
            return myDate.ToString("dd-MM-yyyy");
        }

        public static DateTime ConvertDateTime(string str)
        {
            return DateTime.ParseExact(str, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
        }

        public static T ReadfileJson<T>(string path)
        {
            return JsonConvert.DeserializeObject<T>(System.IO.File.ReadAllText(path));
        }

        public static void SavefileJson(object obj, string path)
        {
            System.IO.File.WriteAllText(path, JsonConvert.SerializeObject(obj));
            Console.WriteLine("save file json is success!");
        }

        public static void SaveObject(object serialize, string path)
        {
            using (Stream stream = File.Open(path, FileMode.Create))
            {
                new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter().Serialize(stream, serialize);
                Console.WriteLine("save file object is success!");
            }
        }

        public static object ReadObject(string path)
        {
            using (Stream stream = File.Open(path, FileMode.Open))
            {
                return new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter().Deserialize(stream);
            }
        }
    }
}


avatar
Nam20021608 [community,AAHN-C2009G]
2021-10-14 07:13:49


#Program.cs


using System;
using lap11.Interface;
using lap11.libary;
using lap11.Model;
using System.Collections.Generic;
using lap11.Manger;

namespace lap11
{
    class Program{
    
        static readonly ColorManager c = new ColorManager();
        static readonly CatManager m = new CatManager();

        static void ShowMenu()
        {
            Console.WriteLine("0. List all colors\n" +
                "1. Input Cats\n" +
                "2. Display Cats\n" +
                "3. Sort by Colors\n" +
                "4. Find by Type\n" +
                "5. Sort Colors in Color list\n" +
                "6. Exit\n");
        }
        static void ListMenu()
        {
            int choose;
            do
            {
                ShowMenu();
                Console.WriteLine("Decide an input");
                choose = Utility.choose();
                switch (choose)
                {
                    case 0:
                        InputColor();
                        break;
                    case 1:
                        InputCat();
                        break;
                    case 2:
                        Display();
                        break;
                    case 3:
                        SortByColor();
                        break;
                    case 4:
                        FindByType();
                        break;
                    case 5:
                        SortByColorFromColorManager();
                        break;
                    case 6:
                        Console.WriteLine("Exits");
                        return;
                    default:
                        Console.WriteLine("Value must be 1->6");
                        break;
                }

            } while (choose != 6);
        }

        private static void SortByColorFromColorManager()
        {
            m.CatList.Sort((a, b) => b.CompareTo(a));
            foreach (CatDetail c in m.CatList)
            {
                c.hienthi();
            }
        }

        private static void SortByColor()
        {

            m.CatList.Sort((a, b) => b.CompareTo(a));
            foreach (CatDetail c in m.CatList)
            {
                c.hienthi();
            }
        }

        private static void FindByType()
        {
            Console.WriteLine("Find Cats by their types:");
            string Find = Console.ReadLine();
            int Count = 0;
            foreach (CatDetail c in m.CatList)
            {
                if (c.Loai.Equals(Find))
                {
                    c.hienthi();
                    Count++;
                }
            }
            if (Count == 0)
            {
                Console.WriteLine("No result found");
            }
        }

        private static void Display()
        {
            m.Display();
        }

        private static void InputCat()
        {
                        
            m.Input();
        }

        private static void InputColor()
        {
            c.Input();
        }
        static void Main(string[] args)
        {
            ListMenu();
        }
    }
}


#CatDetail.cs


using System;
using lap11.Interface;
namespace lap11.Model  {
    class CatDetail : ICat{
        public String Loai{get;set;}
        public String Mau{get;set;}
        public String Noisong{get;set;}

        public CatDetail(){}
        public CatDetail(String loai, String mau , String noisong){
            this.Loai = loai;
            this.Mau = mau;
            this.Noisong = noisong;
        }

        public void hienthi()
        {
            Console.WriteLine("Loai Meo: {0} , Mau : {1} , Noi Song: {2}",Loai,Mau,Noisong);
        }

        public void nhap()
        {
            Console.WriteLine("Nhap Loai meo: ");
            Loai = Console.ReadLine();
            Console.WriteLine("Nhap noi song: ");
            Noisong = Console.ReadLine();
        }

         public int CompareTo(CatDetail other)
        {
            if (Mau.CompareTo(other.Mau) != 0)
            {
                return Mau.CompareTo(other.Mau);
            }
            else
            {
                return 0;
            }
        }
    }
}


#ColorManager.cs


using System;
using System.Collections.Generic;
using lap11.Interface;
using lap11.libary;
namespace lap11.Model
{
    class ColorManager{
        public List<string> colorList{get;set;}
        public String color{get;set;}

        public ColorManager(){}

        public void Input(){
            Console.WriteLine("Nhap so luong mau can them");
            int b = Utility.choose();
            for(int i= 0 ; i< b ; i++){
                Console.WriteLine("Nhap ma mau: ");
                String color = Console.ReadLine();
                colorList.Add(color);
            }
        }
        public void Display(){
            Console.WriteLine("Color: ");
            foreach(String c in colorList){
                Console.Write(c+ " , ");
            }
        }
    }
}


#CatManager.cs


using System;
using lap11.Interface;
using lap11.libary;
using lap11.Model;
using System.Collections.Generic;
namespace lap11.Manger{
    class CatManager{
        public List<CatDetail> CatList { get; set; }
        public CatManager()
        {
            CatList = new List<CatDetail>();
        }
        public void Input()
        {
            Console.WriteLine("Input the amount of cats to be added:");
            int N = Utility.choose();
            for (int i = 0; i < N; i++)
            {
                Console.WriteLine("Cat[" + (i + 1) + "]");
                CatDetail c = new CatDetail();
                c.nhap();
                CatList.Add(c);
            }

        }
        public void Display()
        {
            foreach (CatDetail c in CatList)
            {
                c.hienthi();
            }
        }
    }
}


#Utility.cs


using System;
namespace lap11.libary
{
    class Utility
    {
        public static int choose()
        {
            int a;
            while (true)
            {
                try
                {
                    a = int.Parse(Console.ReadLine());
                    return a;
                }
                catch (System.Exception)
                {

                    Console.WriteLine("Nhap lai!!");
                }
            }
        }

    }
}


#ICat.cs


using System;
namespace lap11.Interface
{
    public interface ICat{
        void nhap();
        void hienthi();
    }
}


avatar
Hoàng Thiện Thanh [community,AAHN-C2009G]
2021-10-13 12:00:06


#Utility.cs


using System;
using System.Text.RegularExpressions;

namespace CatManager.Utils
{
    public class Utility
    {
        public static int ReadInt()
        {
            string str = Console.ReadLine();
            bool check()
            {
                try { int.Parse(str); } catch (Exception) { return false; }
                return true;
            }
            while (!check())
            {
                Console.WriteLine("Cannot parse input like a floor numeric value");
                str = Console.ReadLine();
            }
            return int.Parse(str);
        }
        public static DateTime ReadDate()
        {
            string str = Console.ReadLine();
            DateTime date = new DateTime();
            bool check()
            {
                int ERR = 0;
                try { date = DateTime.Parse(str); } catch (Exception) { ERR++; }
                try { if (ERR == 1) date = Convert.ToDateTime(str); } catch (Exception) { ERR++; }
                if (ERR == 2)
                {
                    return false;
                }
                return true;
            }
            while (!check())
            {
                Console.WriteLine("Cannot read DateTime from input");
                str = Console.ReadLine();
            }
            return date;
        }
        public static string ReadLetters()
        {
            string str = Console.ReadLine();
            while (!Regex.Match(str, "^([a-zA-Z]+|[a-zA-Z]+\\s[a-zA-Z]+)*$").Success)
            {
                Console.WriteLine("Input does not only contain letters");
                str = Console.ReadLine();
            }
            return str;
        }
    }
}


#Program.cs



using CatManager.Managers;
using CatManager.Models;
using CatManager.Utils;
using System;

namespace CatManager
{
    public class Program
    {
        static readonly ColorManager c = new ColorManager();
        static readonly ManagerCat m = new ManagerCat();

        static void ShowMenu()
        {
            Console.WriteLine("0. List all colors\n" +
                "1. Input Cats\n" +
                "2. Display Cats\n" +
                "3. Sort by Colors\n" +
                "4. Find by Type\n" +
                "5. Sort Colors in Color list\n" +
                "6. Exit\n");
        }
        static void ListMenu()
        {
            int choose;
            do
            {
                ShowMenu();
                Console.WriteLine("Decide an input");
                choose = Utility.ReadInt();
                switch (choose)
                {
                    case 0:
                        InputColor();
                        break;
                    case 1:
                        InputCat();
                        break;
                    case 2:
                        Display();
                        break;
                    case 3:
                        SortByColor();
                        break;
                    case 4:
                        FindByType();
                        break;
                    case 5:
                        SortByColorFromColorManager();
                        break;
                    case 6:
                        Console.WriteLine("Exits");
                        return;
                    default:
                        Console.WriteLine("Value must be 1->6");
                        break;
                }

            } while (choose != 6);
        }

        private static void SortByColorFromColorManager()
        {
            m.CatList.Sort((a, b) => b.CompareTo(a));
            foreach (Cat c in m.CatList)
            {
                c.Display();
            }
        }

        private static void SortByColor()
        {

            m.CatList.Sort((a, b) => b.CompareTo(a));
            foreach (Cat c in m.CatList)
            {
                c.Display();
            }
        }

        private static void FindByType()
        {
            Console.WriteLine("Find Cats by their types:");
            string Find = Console.ReadLine();
            int Count = 0;
            foreach (Cat c in m.CatList)
            {
                if (c.Type.Equals(Find))
                {
                    c.Display();
                    Count++;
                }
            }
            if (Count == 0)
            {
                Console.WriteLine("No result found");
            }
        }

        private static void Display()
        {
            m.Display();
        }

        private static void InputCat()
        {
            if (ColorManager.ColorList.Count == 0)
            {
                return;
            }            
            m.Input();
        }

        private static void InputColor()
        {
            c.Input();
        }
        static void Main(string[] args)
        {
            ListMenu();
        }
    }
}


#ICat.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CatManager.Interfaces
{
    interface ICat
    {
        public void Input();
        public void Display();
    }
}


#CatManager.cs


using CatManager.Models;
using CatManager.Utils;
using System;
using System.Collections.Generic;

namespace CatManager.Managers
{
    class ManagerCat
    {
        public List<Cat> CatList { get; set; }
        public ManagerCat()
        {
            CatList = new List<Cat>();
        }
        public void Input()
        {
            Console.WriteLine("Input the amount of cats to be added:");
            int N = Utility.ReadInt();
            for (int i = 0; i < N; i++)
            {
                Console.WriteLine("Cat[" + (i + 1) + "]");
                Cat c = new Cat();
                c.Input();
                CatList.Add(c);
            }

        }
        public void Display()
        {
            foreach (Cat c in CatList)
            {
                c.Display();
            }
        }
    }
}


#ColorManager.cs


using CatManager.Utils;
using System;
using System.Collections.Generic;

namespace CatManager.Managers
{
    public class ColorManager
    {
        public static List<string> ColorList { get; set; }
        public ColorManager()
        {
            ColorList = new List<string>();
        }
        public ColorManager(List<string> colorlist)
        {
            ColorList = colorlist;
        }
        public void Input()
        {
            Console.WriteLine("Input the amount of colors to be added:");
            int N = Utility.ReadInt();
            for (int i = 0; i < N; i++)
            {
                Console.WriteLine("Enter Color "+ (i + 1) + ":");
                string C = Console.ReadLine();
                ColorList.Add(C);
            }
        }
        public void Display()
        {
            string print = "";
            Console.WriteLine("Color :");
            foreach (string c in ColorList)
            {
                print += c + " , ";
            }
            print = print.Remove(print.Length - 1);
            Console.Write(print + ".");
        }
    }

}



#Cat.cs


using CatManager.Interfaces;
using CatManager.Managers;
using CatManager.Utils;
using System;

namespace CatManager.Models
{
    class Cat : ICat
    {
        public string Type { get; set; }
        private string color;
        public string Color
        {
            get
            {
                return color;
            }
            set
            {
                while (!ColorManager.ColorList.Contains(value))
                {
                    Console.WriteLine("No matching color found");
                    value = Console.ReadLine();
                }
                color = value;
            }
        }
        public string Address { get; set; }
        public Cat()
        {

        }
        public Cat(string Type, string Color, string Address)
        {
            this.Type = Type;
            this.Color = Color;
            this.Address = Address;
        }
        public void Display()
        {
            Console.WriteLine("Type :{0}\nColor: {1}\nAddress :{2}", Type, Color, Address);
        }

        public void Input()
        {
            Console.WriteLine("Enter Type :");
            Type = Console.ReadLine();
            Console.WriteLine("Enter Color :");
            Color = Utility.ReadLetters();
            Console.WriteLine("Enter Address :");
            Address = Console.ReadLine();
        }

        public int CompareTo(Cat other)
        {
            if (Color.CompareTo(other.Color) != 0)
            {
                return Color.CompareTo(other.Color);
            }
            else
            {
                return 0;
            }
        }
    }
}



avatar
Nguyễn Việt Hoàng [community,AAHN-C2009G]
2021-10-12 18:28:36


#Cat.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ss10.B2
{
    class Cat : ICat
    {
        public string Type { get; set; }
        private string color;
        public string Color
        {
            get
            {
                return this.color;
            }
            set
            {
                //List<string> ColorVariant 
                while (!ColorManager.ColorList.Contains(value))
                {
                    Console.WriteLine("No matching color found");
                    value = Console.ReadLine();
                }
                
                this.color = value;
                
            }
        }
        public string Address { get; set; }
        public Cat()
        {

        }
        public Cat(string type, string color, string address)
        {
            this.Type = type;
            this.Color = color;
            this.Address = address;
        }
        public void Display()
        {
            Console.WriteLine("Type :{0}, Color: {1}, Address :{2}", Type, Color, Address);
        }

        public void Input()
        {
            Console.WriteLine("Enter Type :");
            Type = Console.ReadLine();
            Console.WriteLine("Enter Color :");
            Color = Console.ReadLine();
            Console.WriteLine("Enter Address :");
            Address = Console.ReadLine();
        }

        public int CompareTo(Cat other)
        {
            if (this.Color.CompareTo(other.Color) != 0)
            {
                return this.Color.CompareTo(other.Color);
            }
            else
            {
                return 0;
            }
        }
    }
}


#ColorManager.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ss10.B2
{
    class ColorManager
    {
        public static List<string> ColorList { get; set; }
        public ColorManager()
        {
            ColorList = new List<string>();
        }
        public ColorManager(List<string> colorlist)
        {
            ColorList = colorlist;
        }
        public void Input()
        {
            Console.WriteLine("Enter Sum Of Color :");
            int sum = int.Parse(Console.ReadLine());
            for (int i = 0; i < sum; i++)
            {
                Console.WriteLine("Color[" + (i + 1) + "]");
                Console.WriteLine("Enter Color :");
                string color = Console.ReadLine();
                ColorList.Add(color);
            }
        }
        public void Display()
        {
            string print = "";
            Console.WriteLine("Color :");
            foreach (string c in ColorList)
            {
                print += c + " , ";
            }
            print = print.Remove(print.Length - 1);
            Console.Write(print + ".");
            
            

            

        }
    }

}



#ICat.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ss10.B2
{
    interface ICat
    {
        public void Input();
        public void Display();
    }
}


#Mains.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ss10.B2
{
    class Mains
    {
        //public static List<ColorManager> ColorList = new List<ColorManager>();
       // public static List<ManagerCat> CatList = new List<ManagerCat>();
        static ColorManager c = new ColorManager();
        static ManagerCat m = new ManagerCat();
        static void ShowMenu()
        {
            Console.WriteLine("0.Enter List Color ");
            Console.WriteLine("1.Enter Information Sum Of Cat");
            Console.WriteLine("2.Display");
            Console.WriteLine("3.Sort By Color");
            Console.WriteLine("4.Find By Type");
            Console.WriteLine("5.Sort By Color from ColorManager");
            Console.WriteLine("6.Exits");
        }
        static void ListMenu()
        {
            int choose;
            do
            {
                ShowMenu();
                Console.WriteLine("Enter choose value");
                choose = int.Parse(Console.ReadLine());
                switch (choose)
                {
                    case 0:
                        InputColor();
                        break;
                    case 1:
                        InputCat();
                        break;
                    case 2:
                        Display();
                        break;
                    case 3:
                        SortByColor();
                        break;
                    case 4:
                        FindByType();
                        break;
                    case 5:
                        SortByColorFromColorManager();
                        break;
                    case 6:
                        Console.WriteLine("Exits");
                        return;
                    default:
                        Console.WriteLine("Value must be 1->6");
                        break;
                }

            } while (choose != 6);
        }

        private static void SortByColorFromColorManager()
        {
            ManagerCat.catList.Sort((a, b) => b.CompareTo(a));
            // save.Sort(
            //     (p1, p2) => (p1.YearPublishing < p2.YearPublishing) ? 1 : -1
            //   );
            foreach (Cat c in ManagerCat.catList)
            {
                c.Display();
            }
        }

        private static void SortByColor()
        {

            ManagerCat.catList.Sort((a, b) => b.CompareTo(a));
           // save.Sort(
              //     (p1, p2) => (p1.YearPublishing < p2.YearPublishing) ? 1 : -1
            //   );
            foreach (Cat c in ManagerCat.catList)
            {
                c.Display();
            }
        }

        private static void FindByType()
        {
            Console.WriteLine("Enter Find Information Type :");
            string find = Console.ReadLine();
            int count = 0;
            foreach(Cat c in ManagerCat.catList)
            {
                if (c.Type.Equals(find))
                {
                    c.Display();
                    count++;
                }
            }
            if (count == 0)
            {
                Console.WriteLine("No result found");
            }
        }

        private static void Display()
        {
            m.Display();
        }

        private static void InputCat()
        {
            
            m.Input();
        }

        private static void InputColor()
        {
            
            c.Input();
            
        }

        public static void Main(string[] args)
        {
            ListMenu();
        }
    }
}


#ManagerCat.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ss10.B2
{
    class ManagerCat
    {
        public static List<Cat> catList { get; set; }
        public ManagerCat()
        {
            catList = new List<Cat>();
        }
       public void Input()
        {
            Console.WriteLine("Enter Sum Of Cat :");
            int sum = int.Parse(Console.ReadLine());
            for(int i = 0; i < sum; i++)
            {
                Console.WriteLine("Cat[" + (i + 1) + "]");
                Cat c = new Cat();
                c.Input();
                catList.Add(c);
            }
           
        }
        public void Display()
        {
           foreach(Cat c in catList)
            {
                c.Display();
            }
        }
    }
}