コード例 #1
0
        /**
         * <summary>This method overrides the default 'ToString()' representation of the Student class.</summary>
         *
         * <example>
         * <code>Student sd = new Student("7142", "Ralph", "Dibney", 11, "Silver");
         * sd.ToString();</code></example>
         *
         * <returns>The string representation of the Student object.</returns>
         */
        public override string ToString()
        {
            string subjects = "";

            GetSubjects.ForEach(_ => { subjects += _.ToString() + "\n"; });

            return("\nID: #" + GetStudentID + "\nForename: " + GetForename + "\nSurname: " + GetSurname + "\nYear: " + GetYear + "\nClass: " + GetClassName
                   + "\nSubjects:" + HelperMethods.DynamicSeparator("Subjects:", "+") + "\n" + subjects.Trim() + "\n");
        }
コード例 #2
0
        // Methods.

        /**
         * <summary>This method stores a valid Subject object into the Student object.</summary>
         *
         * <param name="s">Subject object to be added to the student.</param>
         *
         * <example>
         * <code>Student sd = new Student("0021", "Jane", "Harper", 12, "Navy");
         * sd.AddSubjectToStudent(new Subject("PSY4", "Psychology", "C", "A"));</code>
         * A new subject has been added to 'sd'.</example>
         */
        public void AddSubjectToStudent(Subject s)
        {
            if (s != null)
            {
                if (GetSubjects.Count + 1 > ImportMethods.CheckNoSubjectsForYear(GetYear))
                {
                    // Throws an exception if there will be an invalid number of subjects for a student (dependent on the year).
                    throw new ArgumentException("Invalid number of subjects for Year: " + GetYear + " student!");
                }
                else
                {
                    // Throws an exception if the subject already exists within the Student object.
                    GetSubjects.ForEach(subject => { if (subject.GetSubjectID == s.GetSubjectID)
                                                     {
                                                         throw new ArgumentException("Subject already exists!");
                                                     }
                                        });

                    GetSubjects.Add(s);
                }
            }
        }