Ejemplo n.º 1
0
        private static void EnterGrades(Ibook book)
        {
            while (true)
            {
                Console.WriteLine("Enter a grade or 'Q' to quit ");
                var input = Console.ReadLine();
                if (input == "q")
                {
                    break;
                }

                try
                {
                    var grade = double.Parse(input);
                    book.AddGrade(grade);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (FormatException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    Console.WriteLine("**");
                }
            }
        }
Ejemplo n.º 2
0
        private static bool EnterGrades(Ibook book, bool done)
        {
            while (!done)
            {
                System.Console.WriteLine("Please enter a grade or 'q' to quit: ");
                var input = Console.ReadLine();

                if (input.ToLower() == "q")
                {
                    done = true;
                    break;
                }
                else
                {
                    try
                    {
                        double grade = double.Parse(input);
                        book.AddGrade(grade);
                    }

                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    catch (FormatException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    finally
                    {
                        Console.WriteLine("");
                    }
                }
            }

            return(done);
        }