Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum specialties
- {
- Informatic,HR,QualityAssurance
- }
- public enum universities
- {
- SofiaUniversity,Telerik
- }
- public enum faculties
- {
- RocketScience,AlienHunting
- }
- class Student : ICloneable
- {
- #region Properties
- public string FisrtName { get; private set;}
- public string MidName { get; private set; }
- public string LastName { get; private set; }
- public int SSN { get; private set; }
- public string MobilePfone { get; private set; }
- public string Course { get; private set; }
- public specialties Specialty { get; private set; }
- public universities University { get; private set; }
- public faculties Faculty { get; private set; }
- #endregion
- #region Methods
- public override bool Equals(object obj)
- {
- Student student = obj as Student;
- if (student == null)
- {
- return false;
- }
- //compare reference types
- if (!object.Equals(this.FisrtName, student.FisrtName))
- {
- return false;
- }
- if (!object.Equals(this.MidName, student.MidName))
- {
- return false;
- }
- if (!object.Equals(this.LastName, student.LastName))
- {
- return false;
- }
- //compare value types
- if (this.SSN != student.SSN)
- {
- return false;
- }
- return true;
- }
- public override int GetHashCode()
- {
- return this.FisrtName.GetHashCode() ^ this.SSN.GetHashCode();
- }
- public override string ToString()
- {
- return string.Format("First name: {0}, midle name: {1}, last name: {2}, SSN: {3}, mobile pfone: {4}, course: {5}, specialty: {6}, university: {7}, faculty: {8}",
- this.FisrtName,this.MidName,this.LastName, this.SSN,this.MobilePfone,this.Course,this.Specialty,this.University,this.Faculty);
- }
- //operators
- public static bool operator ==(Student st1, Student st2)
- {
- return object.Equals(st1, st2);
- }
- public static bool operator !=(Student st1, Student st2)
- {
- return !object.Equals(st1, st2);
- }
- //deep clone
- public object Clone()
- {
- return new Student(FisrtName = this.FisrtName,MidName= this.MidName,LastName = this.LastName,SSN = this.SSN, MobilePfone = this.MobilePfone,Course = this.Course,
- Specialty = this.Specialty, University = this.University, Faculty = this.Faculty);
- }
- //CompareTo()
- public int CompareTo(Student student)
- {
- if (this.FisrtName != student.FisrtName)
- {
- return (this.FisrtName.CompareTo(student.FisrtName));
- }
- if (this.MidName != student.MidName)
- {
- return (this.MidName.CompareTo(student.MidName));
- }
- if (this.LastName != student.LastName)
- {
- return (this.LastName.CompareTo(student.LastName));
- }
- if (this.SSN != student.SSN)
- {
- return (this.SSN - student.SSN);
- }
- return 0;
- }
- //compare
- public static List<Student> Compare(List<Student> studentList)
- {
- return studentList.OrderBy(x => x.FisrtName).ThenBy(x => x.MidName).ThenBy(x => x.LastName).ThenBy(x => x.SSN).ToList();
- }
- #endregion
- #region Constructors
- public Student(string fName, string mName, string lName, int ssn, string mobilePfone, string course, specialties specialty, universities university, faculties faculty)
- {
- this.FisrtName = fName;
- this.MidName = mName;
- this.LastName = lName;
- this.SSN = ssn;
- this.MobilePfone = mobilePfone;
- this.Course = course;
- this.Specialty = specialty;
- this.University = university;
- this.Faculty = faculty;
- }
- #endregion
- }
- public interface ICloneable
- {
- object Clone();
- }
- public interface IComparable
- {
- void Compare();
- }
- static void Main()
- {
- Student st1 = new Student(null,"Mishev","Petrov",100,"0888345678", "2a", specialties.HR , universities.SofiaUniversity , faculties.RocketScience);
- Student st2 = new Student(null, "Mishev", "Petrov", 100, "0888345678", "2a", specialties.HR, universities.SofiaUniversity, faculties.RocketScience);
- Student st3 = new Student("Mahmud", "Mishev", "Petrov", 999, "0888345678", "4a", specialties.HR, universities.SofiaUniversity, faculties.RocketScience);
- //test equals
- Console.WriteLine(st1.Equals(st2));
- Console.WriteLine(st1.Equals(st3));
- //test tostring
- Console.WriteLine(st1.ToString());
- //test operators
- Console.WriteLine(st1 == st2);
- Console.WriteLine(st1 != st2);
- //test get hash code
- Console.WriteLine(st3.GetHashCode());
- //test clone
- Student cloned = st1.Clone() as Student;
- //test CompareTo
- Console.WriteLine(st1.CompareTo(st2));
- //test compare
- List<Student> studentList = new List<Student>(new Student[] {st1, st2, st3});
- var sorted = Student.Compare(studentList);
- }
Advertisement
Add Comment
Please, Sign In to add comment