Beispiel #1
0
        public bool carNumberValidation(CarOwner carOwner)
        {
            Regex nameRegex = new Regex(@"KZ[0-9]{3}[A-Z]{3}\d{2}");

            if (nameRegex.IsMatch(carOwner.GetCarNumber()))
            {
                Console.WriteLine("Car number is correct");
                return(true);
            }
            else
            {
                Console.WriteLine("Car number is incorrect");
                return(false);
            }
        }
Beispiel #2
0
        public bool brandValidation(CarOwner carOwner)
        {
            Regex nameRegex = new Regex(@"[A-Za-z]{3,15}");

            if (nameRegex.IsMatch(carOwner.GetBrand()))
            {
                Console.WriteLine("Brand is correct");
                return(true);
            }
            else
            {
                Console.WriteLine("Brand is incorrect");
                return(false);
            }
        }
Beispiel #3
0
        public static void GetCarCount(string brand)
        {
            List <CarOwner> carOwnersList = CarOwner.GetInfoFromFile(@"K:\Epam C Sharp dot net\textFile2.txt");
            List <string>   dataList      = new List <string>();
            int             count         = 0;

            foreach (CarOwner carOwner in carOwnersList)
            {
                if (carOwner.GetBrand().Equals(brand))
                {
                    count++;
                }
            }
            Console.WriteLine("The cars count:");
            Console.WriteLine(brand + " " + count + " car(s)");
            if (dataList.Count == 0)
            {
                Console.WriteLine("There isn't information with such data");
            }
        }
Beispiel #4
0
        public static List <CarOwner> GetInfoFromFile(string path)
        {
            string[]        lines         = File.ReadAllLines(path);
            List <CarOwner> carOwnersList = new List <CarOwner>();

            for (int i = 0; i < lines.Length; i++)
            {
                string[] datas = new string[lines.Length];
                datas = lines[i].Split(' ');
                CarOwner carOwner = new CarOwner(datas[0], datas[1], datas[2]);
                carOwnersList.Add(carOwner);
            }


            //foreach(CarOwner owner in carOwnersList)
            //    {
            //    Console.WriteLine(owner.GetCarNumber());
            //}
            return(carOwnersList);
        }
Beispiel #5
0
        public static void GetInfoByBrand(string brand)
        {
            List <CarOwner> carOwnersList = CarOwner.GetInfoFromFile(@"K:\Epam C Sharp dot net\textFile2.txt");
            List <string>   dataList      = new List <string>();

            foreach (CarOwner carOwner in carOwnersList)
            {
                if (carOwner.GetBrand().Equals(brand))
                {
                    string data = carOwner.GetName() + " " + carOwner.GetCarNumber();
                    dataList.Add(data);
                }
            }
            Console.WriteLine("Car owners name and car number:");
            foreach (string data in dataList)
            {
                Console.WriteLine(data);
            }
            if (dataList.Count == 0)
            {
                Console.WriteLine("There isn't information with such data");
            }
        }
Beispiel #6
0
        public static void GetInfoByRegionNumber(string region)
        {
            List <CarOwner> carOwnersList = CarOwner.GetInfoFromFile(@"K:\Epam C Sharp dot net\textFile2.txt");
            List <string>   dataList      = new List <string>();

            foreach (CarOwner carOwner in carOwnersList)
            {
                string regionNumber = carOwner.GetCarNumber().Substring(carOwner.GetCarNumber().Length - 2);
                if (regionNumber.Equals(region))
                {
                    string data = carOwner.GetName();
                    dataList.Add(data);
                }
            }
            Console.WriteLine("Car owners name:");
            foreach (string data in dataList)
            {
                Console.WriteLine(data);
            }
            if (dataList.Count == 0)
            {
                Console.WriteLine("There isn't information with such data");
            }
        }