//pagalbinis metodas sugeneruoto failo nuskaitymui
        public static Studentas ToObjectFromLineGen(string Line)
        {
            string[] SeparatedWords = Line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            double   FinGrade       = 6;

            try
            {
                if (SeparatedWords.Length == 3)
                {
                    FinGrade = double.Parse(SeparatedWords[2]);
                }
                else
                {
                    throw new Exception("WrongFileFormatException");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("kursiokaiXX.txt failo formatas neteisingas, turi būti nurodyti vardas, pavardė ir galutinis pažymys");
                Environment.Exit(0);
            }
            Studentas StudentObject = new Studentas(SeparatedWords[0], SeparatedWords[1], FinGrade);

            return(StudentObject);
        }
        //pagalbinis metodas studentai.txt failo nuskaitymui
        public static Studentas ToObjectFromLine(string Line)
        {
            string[]   SeparatedWords = Line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            int        ExamGrade      = int.Parse(SeparatedWords[(SeparatedWords.Length - 1)]);
            List <int> grades         = new List <int>();

            try
            {
                if (SeparatedWords.Length >= 4)
                {
                    for (int i = 2; i < SeparatedWords.Length - 1; i++)
                    {
                        grades.Add(int.Parse(SeparatedWords[i]));
                    }
                }
                else
                {
                    throw new Exception("WrongFileFormatException");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("kursiokai.txt failo formatas neteisingas, turi būti nurodyti vardas, pavardė, mažiausiai vienas ND pažymys ir egzamino įvertinimas");
                Environment.Exit(0);
            }
            Studentas StudentObject = new Studentas(SeparatedWords[0], SeparatedWords[1], ExamGrade, grades);

            return(StudentObject);
        }
        //prideti studenta prie konteinerio atmintyje
        private static void AddStudent(List <Studentas> Studentai)
        {
            Console.Write("Iveskite studento varda: "); string   vard = Console.ReadLine();
            Console.Write("Iveskite studento pavarde: "); string pav  = Console.ReadLine();
            if (!(vard.All(char.IsLetter)) || !(pav.All(char.IsLetter)))
            {
                Console.WriteLine("Vardas ir pavarde privalo susideti tik is raidziu");
                AddStudent(Studentai);
            }
            Console.Write("Iveskite studento egzamino pazymi: ");
            try
            {
                egz = int.Parse(Console.ReadLine());
                if (egz < 1 || egz > 10)
                {
                    throw new Exception("GradeOutOfBoundsException");
                }
            }
            catch (FormatException ex)
            {
                Console.WriteLine("Ivedimo klaida, iveskite sveika skaiciu");
                AddStudent(Studentai);
            } catch (Exception ex) { Console.WriteLine("Ivestas blogas egzamino pazymys"); AddStudent(Studentai); }

            Studentas stud = new Studentas(vard, pav, egz);

            Console.WriteLine("iveskite 1, kad sugeneruoti atsitiktinius pazymius, iveskite kita skaiciu, kad ivesti pazymius ranka");
            try { sel = int.Parse(Console.ReadLine()); }
            catch (Exception ex)
            {
                Console.WriteLine("Ivedimo klaida, iveskite skaiciu.");
                AddStudent(Studentai);
            }
            if (sel == 1)
            {
                Console.WriteLine("Kiek pazymiu sugeneruoti?");
                try { kiek = int.Parse(Console.ReadLine()); }
                catch (Exception ex)
                {
                    Console.WriteLine("Ivedimo klaida, iveskite skaiciu.");
                    AddStudent(Studentai);
                }
                stud.GeneratePazymiai(kiek);
            }
            else
            {
                stud.AddPazymiai();
            }
            Studentai.Add(stud);
        }
 //viesas metodas naudojamas greicio skaiciavime
 public static void GenerateStudents(int studn)
 {
     try
     {
         Random rnd = new Random();
         string TempName, TempSurn;
         System.IO.StreamWriter outfile = new System.IO.StreamWriter("../../kursiokai" + studn + ".txt", true);
         outfile.WriteLine("{0,-15}{1,-15}{2,16}\n----------------------------------------------", "Vardas", "Pavarde", "Galutinis");
         for (int i = 1; i <= studn; i++)
         {
             TempName = "Vardas" + i; TempSurn = "Pavarde" + i;
             Studentas TempStud = new Studentas(TempName, TempSurn, Math.Round(rnd.NextDouble() * (10.0f - 2.0f) + 2.0f));
             outfile.WriteLine("{0,-15}{1,-15}{2,16}", TempStud.Vardas, TempStud.Pavarde, TempStud.Bendras);
         }
         outfile.Flush(); outfile.Close();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Ivyko klaida, {0}", ex.Message);
         GenerateStudents(studn);
     }
 }
 //privatus metodas sugeneruoti studento faila
 private static void GenerateStudents()
 {
     Console.WriteLine("Kiek studentų sugeneruoti?");
     try
     {
         Random rnd = new Random();
         string TempName, TempSurn;
         int    stud = int.Parse(Console.ReadLine());
         System.IO.StreamWriter outfile = new System.IO.StreamWriter("../../kursiokai" + stud + ".txt", true);
         outfile.WriteLine("{0,-15}{1,-15}{2,16}\n----------------------------------------------", "Vardas", "Pavarde", "Galutinis");
         for (int i = 1; i <= stud; i++)
         {
             TempName = "Vardas" + i; TempSurn = "Pavarde" + i;
             Studentas TempStud = new Studentas(TempName, TempSurn, Math.Round(rnd.NextDouble() * (10.0f - 2.0f) + 2.0f));
             outfile.WriteLine("{0,-15}{1,-15}{2,16}", TempStud.Vardas, TempStud.Pavarde, TempStud.Bendras);
         }
         outfile.Flush(); outfile.Close();
     } catch (Exception ex)
     {
         Console.WriteLine("Ivedimo klaida, iveskite sveika skaiciu");
         GenerateStudents();
     }
 }
        //viesas metodas naudojamas greicio skaiciavime
        public static void SplitStudentFile(int studnum)
        {
            List <Studentas> Studentai     = new List <Studentas>();
            List <Studentas> StudentaiNusk = new List <Studentas>();
            List <Studentas> StudentaiGud  = new List <Studentas>();

            Studentai = FileReader.ReadFile("../../kursiokai" + studnum + ".txt");

            for (int i = Studentai.Count - 1; i >= 0; i--)
            {
                Studentas stud = Studentai[i];
                if (stud.Bendras < 5.0f)
                {
                    StudentaiNusk.Add(stud);
                }
                else
                {
                    StudentaiGud.Add(stud);
                }
            }
            Studentai     = null;
            StudentaiGud  = StudentaiGud.OrderBy(x => x.Bendras).ToList();
            StudentaiNusk = StudentaiNusk.OrderBy(x => x.Bendras).ToList();
            System.IO.StreamWriter outfile  = new System.IO.StreamWriter("../../gudruoliai" + studnum + ".txt", true);
            System.IO.StreamWriter outfile1 = new System.IO.StreamWriter("../../nuskriaustukai" + studnum + ".txt", true);
            outfile.WriteLine("{0,-15}{1,-15}{2,16}\n----------------------------------------------", "Vardas", "Pavarde", "Galutinis");
            foreach (Studentas stud in StudentaiGud)
            {
                outfile.WriteLine("{0,-15}{1,-15}{2,16}", stud.Vardas, stud.Pavarde, stud.Bendras);
            }
            outfile1.WriteLine("{0,-15}{1,-15}{2,16}\n----------------------------------------------", "Vardas", "Pavarde", "Galutinis");
            foreach (Studentas stud in StudentaiNusk)
            {
                outfile1.WriteLine("{0,-15}{1,-15}{2,16}", stud.Vardas, stud.Pavarde, stud.Bendras);
            }
            outfile.Flush(); outfile1.Flush(); outfile.Close(); outfile1.Close();
        }