示例#1
0
        public void TestStudentConstructor4()
        {
            Student charlie = new Student(
                "Charles",
                "James",
                "Stuart",
                "721-07-4426",
                "151 South Almaden Boulevard, San Jose, California",
                "020 7290 7701",
                "*****@*****.**",
                3,
                Speciality.Architecture,
                University.MassachusettsInstituteOfTechnology,
                School.ArchitectureAndPlanning);

            Assert.AreEqual("721-07-4426", charlie.Ssn);
        }
        public static void Main()
        {
            Student peter = new Student("Peter", "Ivanov");
            peter.DateOfBirth = new DateTime(1992, 3, 17);
            peter.Town = "Sofia";

            Student stella = new Student("Stella", "Markova");
            stella.DateOfBirth = new DateTime(1993, 11, 03);
            stella.Town = "Vidin";
            stella.CourseResult = CourseResult.Hight;
            stella.Interest = "gamer";

            Console.WriteLine(
                "{0} older than {1} -> {2}",
                peter.FirstName,
                stella.FirstName,
                peter.IsOlderThan(stella));
        }
示例#3
0
        public static void Main()
        {
            SortedDictionary<string, List<Student>> studentInClasses = new SortedDictionary<string, List<Student>>(); 

            using (StreamReader inputStream = new StreamReader(@"../../student.txt"))
            {
                string line = inputStream.ReadLine();

                while (line != null)
                {
                    string[] splitedLine = line.Split(new char[] { ' ', '|' }, StringSplitOptions.RemoveEmptyEntries);
                    string studentClass = splitedLine[2];
                    Student currentStudent = new Student(splitedLine[0], splitedLine[1]);

                    if (studentInClasses.ContainsKey(studentClass))
                    {
                        studentInClasses[studentClass].Add(currentStudent);
                    }
                    else
                    {
                        studentInClasses.Add(studentClass, new List<Student>() { currentStudent });
                    }

                    line = inputStream.ReadLine();
                }
            }

            foreach (var element in studentInClasses)
            {
                Console.Write("Class: {0} ", element.Key);

                foreach (var student in element.Value)
                {
                    Console.Write(student.ToString());
                }

                Console.WriteLine();
                Console.WriteLine(new string('-', Console.WindowWidth - 2));
            }
        }
        public bool IsOlderThan(Student other)
        {
            DateTime firstDate = this.DateOfBirth;
            DateTime secondDate = other.DateOfBirth;

            bool isOlderThan = firstDate < secondDate;

            return isOlderThan;
        }
示例#5
0
        public void TestStudentCompareToMethod()
        {
            Student[] students = new Student[]
            {
                new Student(
                    "Charles",
                    "James",
                    "Stuart",
                    "721-07-4426",
                    "151 South Almaden Boulevard, San Jose, California",
                    "020 7290 7701",
                    "*****@*****.**",
                    3,
                    Speciality.Architecture,
                    University.MassachusettsInstituteOfTechnology,
                    School.ArchitectureAndPlanning),
                    
                new Student(
                    "Charles",
                    "James",
                    "Stuart",
                    "138-12-7345",
                    "Apple Campus, 1 Infinite Loop, Cupertino, California, U.S.",
                    "032 9871 6346",
                    "*****@*****.**",
                    4,
                    Speciality.OperationsResearch,
                    University.UniversityOfChicago,
                    School.Science)
            };

            Array.Sort(students);

            Assert.AreEqual("138-12-7345", students[0].Ssn);
        }
示例#6
0
        public void TestStudentEqualsMethod2()
        {
            Student charlie1 = new Student(
                "Charles",
                "James",
                "Stuart",
                "721-07-4426",
                "151 South Almaden Boulevard, San Jose, California",
                "020 7290 7701",
                "*****@*****.**",
                3,
                Speciality.Architecture,
                University.MassachusettsInstituteOfTechnology,
                School.ArchitectureAndPlanning);

            Student charlie2 = new Student(
                "Charles",
                "James",
                "Stuart",
                "721-07-4426",
                "Apple Campus, 1 Infinite Loop, Cupertino, California, U.S.",
                "032 9871 6346",
                "*****@*****.**",
                4,
                Speciality.OperationsResearch,
                University.UniversityOfChicago,
                School.Science);

            Assert.AreEqual(true, charlie1.Equals(charlie2));
        }
示例#7
0
        public void TestStudentCloneMethod()
        {
            Student charlie1 = new Student(
                "Charles",
                "James",
                "Stuart",
                "721-07-4426",
                "151 South Almaden Boulevard, San Jose, California",
                "020 7290 7701",
                "*****@*****.**",
                3,
                Speciality.Architecture,
                University.MassachusettsInstituteOfTechnology,
                School.ArchitectureAndPlanning);

            Student charlie2 = charlie1.Clone();

            charlie2.Ssn = "144-04-9020";

            Assert.AreNotEqual("144-04-9020", charlie1.Ssn);
        }
示例#8
0
        public void TestStudentOperatorEquals()
        {
            Student charlie = new Student(
                "Charles",
                "James",
                "Stuart",
                "721-07-4426",
                "151 South Almaden Boulevard, San Jose, California",
                "020 7290 7701",
                "*****@*****.**",
                3,
                Speciality.Architecture,
                University.MassachusettsInstituteOfTechnology,
                School.ArchitectureAndPlanning);

            Student daniel = new Student(
                "Daniel",
                "Ray",
                "Coats",
                "144-04-9020",
                "8050 Microsoft Way, Charlotte, North Carolina",
                "031 7861 9238",
                "*****@*****.**",
                4,
                Speciality.PoliticalScience,
                University.Harvard,
                School.HumanitiesArtsAndSocialSciences);

            Assert.AreEqual(false, charlie == daniel);
        }
示例#9
0
 public void TestStudentConstructor18_ThrowsException()
 {
     Student charlie = new Student(
         "Charles",
         "James",
         "Stuart",
         "721-07-4426",
         "151 South Almaden Boulevard, San Jose, California",
         "020 7290 7701",
         "",
         3,
         Speciality.Architecture,
         University.MassachusettsInstituteOfTechnology,
         School.ArchitectureAndPlanning);
 }
示例#10
0
 public void TestStudentConstructor16_ThrowsException()
 {
     Student charlie = new Student(
         "Charles",
         "James",
         "Stuart",
         "721-07-4426",
         "           ",
         "020 7290 7701",
         "*****@*****.**",
         3,
         Speciality.Architecture,
         University.MassachusettsInstituteOfTechnology,
         School.ArchitectureAndPlanning);
 }