Exemple #1
0
        public static void Main(string[] args)
        {
            var io       = new InteractiveIO(Console.In, Console.Out);
            var students = new ListBasedStudentStore(10);

            BranchMenu(
                Console.In,
                Console.Out,
                Console.Clear,
                io,
                students
                );
        }
Exemple #2
0
        private static Student ReadStudentInteractive(InteractiveIO io)
        {
            string name    = io.ReadUntilValidInputProvided("Name: ", IsValidName);
            string surname = io.ReadUntilValidInputProvided("Surname: ", IsValidName);

            string homeworkGrades = io.ReadUntilValidInputProvided(
                "Homework grades (space separated, 0-10): ",
                IsValidGradeSequence
                );

            string examGrade = io.ReadUntilValidInputProvided(
                "Exam grade (0-10): ",
                IsValidGrade
                );

            return(Student.ParseUnsafe(
                       name,
                       surname,
                       Tokenize(homeworkGrades),
                       examGrade
                       ));
        }
Exemple #3
0
        private static void BranchMenu(
            TextReader reader,
            TextWriter writer,
            ClearOutput clearOut,
            InteractiveIO io,
            IStudentStore students
            )
        {
            clearOut();

            writer.WriteLine("Total students: {0}\n", students.Length);

            writer.WriteLine("Which task would you like to execute?");
            writer.WriteLine("{0}) Add a new student", (int)MenuChoice.AddStudent);
            writer.WriteLine("{0}) Read students from file", (int)MenuChoice.ReadStudentsFile);
            writer.WriteLine("{0}) Print results of students", (int)MenuChoice.PrintResults);
            writer.WriteLine("{0}) Benchmark", (int)MenuChoice.Benchmark);
            writer.WriteLine("{0}) Exit program\n", (int)MenuChoice.Exit);

            writer.Write("Menu choice: ");
#pragma warning disable IDE0018 // Inline variable declaration
            int menuChoice;
#pragma warning restore IDE0018 // Inline variable declaration
            if (!int.TryParse(reader.ReadLine(), out menuChoice))
            {
                writer.WriteLine("Error parsing the choice, please try again...");
                reader.Read();
            }
            else
            {
                switch (menuChoice)
                {
                case (int)MenuChoice.AddStudent: {
                    var student = ReadStudentInteractive(io);
                    students.Add(student);
                    break;
                }

                case (int)MenuChoice.ReadStudentsFile: {
                    var filename = io.ReadLineInteractive("File name: ");
                    AddStudentsFromFile(writer, filename, students);
                    writer.WriteLine("Press any key to continue.");
                    reader.Read();
                    break;
                }

                case (int)MenuChoice.PrintResults: {
                    var sortedStudents = students.All()
                                         .OrderBy(x => x.surname)
                                         .ThenBy(x => x.name);
                    StudentSummaryPrinter.PrintSummary(writer, sortedStudents);
                    reader.Read();
                    break;
                }

                case (int)MenuChoice.Benchmark: {
                    BenchmarkSuite(reader, writer);
                    reader.Read();
                    break;
                }

                case (int)MenuChoice.Exit: return;

                default:
                    writer.WriteLine("Wrong choice, please try again...");
                    reader.Read();
                    break;
                }
            }
            BranchMenu(reader, writer, clearOut, io, students);
        }