Advertisement
Statev

PriorityStudent

Feb 24th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Wintellect.PowerCollections;
  6. using System.Collections;
  7.  
  8. namespace _11.PriorityStudent
  9. {
  10.     public class Student : IComparable
  11.     {
  12.         private string name;
  13.         private int age;
  14.         private bool paidSemesterOnline;
  15.  
  16.         public string Name
  17.         {
  18.             get { return this.name; }
  19.             set { this.name = value; }
  20.         }
  21.         public int Age
  22.         {
  23.             get { return this.age; }
  24.             set { this.age = value; }
  25.         }
  26.  
  27.         public bool PaidSemesterOnline
  28.         {
  29.             get { return this.paidSemesterOnline; }
  30.             set { this.paidSemesterOnline = value; }
  31.         }
  32.  
  33.         public Student()
  34.         {
  35.             age = 0;
  36.             name = "";
  37.             paidSemesterOnline = false;
  38.         }
  39.  
  40.         public Student(int age, string name, bool paidSemesterOnline = false)
  41.         {
  42.             this.age = age;
  43.             this.name = name;
  44.             this.paidSemesterOnline = paidSemesterOnline;
  45.         }
  46.  
  47.         public override string ToString()
  48.         {
  49.             string output = "Student:" + "\r\n";
  50.             output = output + string.Format("    Name: {0}", this.name) + "\r\n";
  51.             output = output + string.Format("    Age: {0}", this.age) + "\r\n";
  52.             output = output + string.Format("    PaidOnline: {0}", this.paidSemesterOnline);
  53.             return output;
  54.         }
  55.  
  56.         public int CompareTo(object obj)
  57.         {
  58.             if (!(obj is Student))
  59.             {
  60.                 throw new ArgumentException(
  61.                 "A Student object is required for comparison.");
  62.             }
  63.             return -1 * this.paidSemesterOnline.CompareTo(((Student)obj).paidSemesterOnline);
  64.         }
  65.     }
  66.  
  67.     class PriorityStudent
  68.     {
  69.         static void Main(string[] args)
  70.         {
  71.             OrderedBag<Student> studentQueue = new OrderedBag<Student>();
  72.             Student pesho = new Student(19,"pesho");
  73.  
  74.             Student kiril = new Student(23,"kiril",true);
  75.  
  76.             Student ivan = new Student(21,"ivan");
  77.  
  78.             studentQueue.Add(pesho);
  79.             studentQueue.Add(kiril);
  80.             studentQueue.Add(ivan);
  81.  
  82.             foreach (var student in studentQueue)
  83.             {
  84.                 Console.WriteLine(student);
  85.             }
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement