Beispiel #1
0
 public void AddStudent(Student student)
 {
     students.Add(student);
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            bool b = true;
            char choice;

            Console.WriteLine("");
            Methods        methods      = new Methods();
            List <Student> studentsList = new List <Student>();
            FileWork       fw           = new FileWork();

            do
            {
                Console.WriteLine("\nPlease, choose an action: ");
                Console.WriteLine("1. Add new student to database");
                Console.WriteLine("2. Show options for database");
                Console.Write("\nYour choice is: ");
                choice = char.Parse(Console.ReadLine());

                switch (choice)
                {
                case '1':
                {
                    Student student = new Student();
                    Console.Write("\nEnter surname of student: ");
                    student.surname = Console.ReadLine();

                    Console.Write("Enter year of birth of student: ");
                    student.birth = int.Parse(Console.ReadLine());

                    Console.Write("Enter group of student: ");
                    student.group = int.Parse(Console.ReadLine());

                    Console.Write("Enter faculty of student: ");
                    student.faculty = Console.ReadLine();

                    methods.AddStudent(student);

                    Console.WriteLine("\nStudent was created!");
                    Console.WriteLine("--------------------------------------------");

                    break;
                }

                case '2':
                {
                    b = false;
                    continue;
                }

                default:
                {
                    Console.WriteLine("Wrong value! Try again...");
                    break;
                }
                }
            } while (b);

            do
            {
                Console.WriteLine("\n\tChoose an action you wanted to do:");
                Console.WriteLine("1 - Students list");
                Console.WriteLine("2 - An average age of students");
                Console.WriteLine("3 - Minimum and maximum age of students");
                Console.WriteLine("4 - Sorting by surname");
                Console.WriteLine("5 - Sorting by year of birth");
                Console.WriteLine("6 - Sorting by group");
                Console.WriteLine("7 - Write students to file");
                Console.WriteLine("8 - Read students from file");
                Console.WriteLine("9 - Exit");
                Console.Write("\nYour choice is: ");
                choice = char.Parse(Console.ReadLine());

                switch (choice)
                {
                case '1':
                {
                    Student student = new Student();
                    studentsList = methods.StudentsList();
                    foreach (Student students in studentsList)
                    {
                        Console.WriteLine("--------------------------------------------");
                        Console.WriteLine("Surname: " + students.surname);
                        Console.WriteLine("Year of birth: " + students.birth);
                        Console.WriteLine("Group: " + students.group);
                        Console.WriteLine("Faculty:" + students.faculty);
                        Console.WriteLine("--------------------------------------------");
                    }
                    break;
                }

                case '2':
                {
                    Console.WriteLine("--------------------------------------------");
                    Console.WriteLine("An average age of students is: " + methods.AverageAge(methods.StudentsList()));
                    Console.WriteLine("--------------------------------------------");
                    break;
                }

                case '3':
                {
                    Console.WriteLine("--------------------------------------------");
                    Console.WriteLine("Maximum age of students is: " + methods.MaxAge(methods.StudentsList()));
                    Console.WriteLine("--------------------------------------------");
                    Console.WriteLine("Minimum age of students is: " + methods.MinAge(methods.StudentsList()));
                    Console.WriteLine("--------------------------------------------");
                    break;
                }

                case '4':
                {
                    Console.WriteLine("--------------------------------------------");
                    methods.SortingBySurname();
                    Console.WriteLine("--------------------------------------------");
                    break;
                }

                case '5':
                {
                    Console.WriteLine("--------------------------------------------");
                    methods.SortingByYearOfBirth();
                    Console.WriteLine("--------------------------------------------");
                    break;
                }

                case '6':
                {
                    Console.WriteLine("--------------------------------------------");
                    methods.SortingByGroup();
                    Console.WriteLine("--------------------------------------------");
                    break;
                }

                case '7':
                {
                    fw.WriteToFile(studentsList);
                    Console.WriteLine("File was written!");
                    break;
                }

                case '8':
                {
                    fw.ReadFromFile();
                    Console.WriteLine("File was read!");
                    break;
                }

                case '9':
                {
                    break;
                }

                default:
                {
                    Console.WriteLine("Wrong value! Try again...");
                    break;
                }
                }
            } while (choice != '9');
        }