Advertisement
svetoslavbozov

[OOP] Common Type System - Задача 1,2,3

Mar 8th, 2013
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.86 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. public enum University
  5. {
  6.     SU, TU, NBU, UNSS
  7. }
  8.  
  9. public enum Faculty
  10. {
  11.     Philosophy, Law, Mathematics, Phisics, Business, Management, Telecommunications
  12. }
  13.  
  14. public enum Specialty
  15. {
  16.     Telecommunications, Marketing, Business, Entrepreneurship, Phisics, Mathematics, Informatics, Law, Philosophy
  17. }
  18.  
  19. public class Student : ICloneable, IComparable<Student>
  20. {
  21.     private string firstName;
  22.     private string middleName;
  23.     private string lastName;
  24.     private string address;
  25.     private int phone;
  26.     private int course;
  27.     private int ssn;
  28.     private Specialty specialty;
  29.     private University university;
  30.     private Faculty faculty;
  31.  
  32.     public string FirstName
  33.     {
  34.         get { return this.firstName; }
  35.         set { this.firstName = value; }
  36.     }
  37.     public string MiddleName
  38.     {
  39.         get { return this.middleName; }
  40.         set { this.middleName = value; }
  41.     }
  42.     public string LastName
  43.     {
  44.         get { return this.lastName; }
  45.         set { this.lastName = value; }
  46.     }
  47.     public string Address
  48.     {
  49.         get { return this.address; }
  50.         set { this.address = value; }
  51.     }
  52.     public int Phone
  53.     {
  54.         get { return this.phone; }
  55.         set { this.phone = value; }
  56.     }
  57.     public int Course
  58.     {
  59.         get { return this.course; }
  60.         set { this.course = value; }
  61.     }
  62.     public Specialty Specialty
  63.     {
  64.         get { return this.specialty; }
  65.         set { this.specialty = value; }
  66.     }
  67.     public University University
  68.     {
  69.         get { return this.university; }
  70.         set { this.university = value; }
  71.     }
  72.     public Faculty Faculty
  73.     {
  74.         get { return this.faculty; }
  75.         set { this.faculty = value; }
  76.     }
  77.     public int SSN
  78.     {
  79.         get { return this.ssn; }
  80.         set { this.ssn = value; }
  81.     }
  82.     public Student()
  83.     {
  84.     }
  85.     public Student(string firstName, string middleName, string lastName, string address, int phone, int course, int ssn, Specialty specialty, University university, Faculty faculty)
  86.     {
  87.         this.FirstName = firstName;
  88.         this.MiddleName = middleName;
  89.         this.LastName = lastName;
  90.         this.Address = address;
  91.         this.Phone = phone;
  92.         this.Course = course;
  93.         this.SSN = ssn;
  94.         this.Specialty = specialty;
  95.         this.University = university;
  96.         this.Faculty = faculty;
  97.     }
  98.     public override string ToString()
  99.     {
  100.         StringBuilder build = new StringBuilder();
  101.         build.AppendLine(this.FirstName);
  102.         build.AppendLine(this.MiddleName);
  103.         build.AppendLine(this.LastName);
  104.         build.AppendLine(this.Address);
  105.         build.AppendLine(this.Phone.ToString());
  106.         build.AppendLine(this.Course.ToString());
  107.         build.AppendLine(this.SSN.ToString());
  108.         build.AppendLine(this.Specialty.ToString());
  109.         build.AppendLine(this.University.ToString());
  110.         build.AppendLine(this.Faculty.ToString());
  111.  
  112.         return build.ToString();
  113.     }
  114.  
  115.     public override bool Equals(object param)
  116.     {
  117.         Student student = param as Student;
  118.  
  119.         if (student == null)
  120.         {
  121.             return false;
  122.         }
  123.  
  124.         if (!Object.Equals(this.FirstName, student.FirstName))
  125.         {
  126.             return false;
  127.         }
  128.  
  129.         if (!Object.Equals(this.LastName, student.LastName))
  130.         {
  131.             return false;
  132.         }
  133.         if (this.SSN != student.SSN)
  134.         {
  135.             return false;
  136.         }
  137.  
  138.         return true;
  139.     }
  140.  
  141.     public static bool operator ==(Student student1, Student student2)
  142.     {
  143.         return Student.Equals(student1, student2);
  144.     }
  145.  
  146.     public static bool operator !=(Student student1, Student student2)
  147.     {
  148.         return !(Student.Equals(student1, student2));
  149.     }
  150.  
  151.     public override int GetHashCode()
  152.     {
  153.         return LastName.GetHashCode() ^ SSN.GetHashCode();
  154.     }
  155.     public Student Clone()
  156.     {
  157.         Student clone = new Student
  158.             (
  159.             this.FirstName,
  160.             this.MiddleName,
  161.             this.LastName,
  162.             this.Address,
  163.             this.Phone,
  164.             this.Course,
  165.             this.SSN,
  166.             this.Specialty,
  167.             this.University,
  168.             this.Faculty
  169.             );
  170.         return clone;
  171.     }
  172.  
  173.     object ICloneable.Clone()
  174.     {
  175.         return this.Clone();
  176.     }
  177.  
  178.     public int CompareTo(Student student)
  179.     {
  180.         if (this.LastName != student.LastName)
  181.         {
  182.             return (String.Compare(this.LastName, student.LastName));
  183.         }
  184.         if (this.FirstName != student.FirstName)
  185.         {
  186.             return (String.Compare(this.FirstName, student.FirstName));
  187.         }
  188.         if (this.SSN != student.SSN)
  189.         {
  190.             return ( this.SSN - student.SSN);
  191.         }
  192.         return 0;
  193.     }    
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement