﻿namespace Exceptions_Homework
{
    using System;

    public class SimpleMathExam : Exam
    {
        private int problemsSolved;

        public SimpleMathExam(int problemsSolved)
        {
            this.ProblemsSolved = problemsSolved;
        }

        public int ProblemsSolved 
        {
            get
            {
                return this.problemsSolved;
            }
            private set
            {
                if (problemsSolved < 0)
                {
                    problemsSolved = 0;
                }

                if (problemsSolved > 10)
                {
                    problemsSolved = 10;
                }

                this.problemsSolved = value;
            }
        }

        public override ExamResult Check()
        {
            try
            {
                if (ProblemsSolved == 0)
                {
                    new ExamResult(2, 2, 6, "Bad result: nothing done.");
                }
                else if (ProblemsSolved == 1)
                {
                    return new ExamResult(4, 2, 6, "Average result: nothing done.");
                }
                else if (ProblemsSolved == 2)
                {
                    return new ExamResult(6, 2, 6, "Average result: nothing done.");
                }

                return new ExamResult(0, 0, 0, "Invalid number of problems solved!");
            }
            catch (ExamException innerException)
            {
                throw new ExamException("Simple math exam Check method trying to return invalid ExamResult", innerException);
            }
        }
    }
}