Advertisement
themkss

Untitled

May 2nd, 2023
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5.  
  6. namespace LB4_V2
  7. {
  8.     /// <summary>
  9.     /// abstract class Publication
  10.     /// </summary>
  11.     public abstract class Publication : IComparable<Publication>, IEquatable<Publication>
  12.     {
  13.         public string name { get; set; }
  14.         public string type { get; set; }
  15.         public string publishingPlace { get; set; }
  16.         public int yearOfRelease { get; set; }
  17.         public int numberOfPages { get; set; }
  18.         public int edition { get; set; }
  19.  
  20.         /// <summary>
  21.         /// Constructor for abstract Publication class
  22.         /// </summary>
  23.         /// <param name="name"></param>
  24.         /// <param name="type"></param>
  25.         /// <param name="publishingPlace"></param>
  26.         /// <param name="yearOfRelease"></param>
  27.         /// <param name="numberOfPages"></param>
  28.         /// <param name="edition"></param>
  29.         protected Publication(string name, string type, string publishingPlace, int yearOfRelease, int numberOfPages, int edition)
  30.         {
  31.             this.name = name;
  32.             this.type = type;
  33.             this.publishingPlace = publishingPlace;
  34.             this.yearOfRelease = yearOfRelease;
  35.             this.numberOfPages = numberOfPages;
  36.             this.edition = edition;
  37.         }
  38.  
  39.         /// <summary>
  40.         /// Overridden method ToString();
  41.         /// </summary>
  42.         /// <returns></returns>
  43.         public override string ToString()
  44.         {
  45.             return String.Format("{0},{1},{2},{3},{4},{5}", this.name, this.type, this.publishingPlace, this.yearOfRelease, this.numberOfPages, this.edition);
  46.         }
  47.  
  48.         /// <summary>
  49.         /// Implemented IComparable<Publication> interface
  50.         /// </summary>
  51.         /// <param name="other"></param>
  52.         /// <returns></returns>
  53.         public int CompareTo(Publication other)
  54.         {
  55.             return this.yearOfRelease.CompareTo(other.yearOfRelease);
  56.         }
  57.  
  58.         /// <summary>
  59.         /// Implemented IEquatable<Publication> interface
  60.         /// </summary>
  61.         /// <param name="other"></param>
  62.         /// <returns></returns>
  63.         public bool Equals(Publication other)
  64.         {
  65.             if(this.name.Equals(other.name) && this.type.Equals(other.type) && this.publishingPlace.Equals(other.publishingPlace)
  66.                 && this.yearOfRelease == other.yearOfRelease && this.numberOfPages == other.numberOfPages && this.edition == other.edition)
  67.             {
  68.                 return true;
  69.             }
  70.             else
  71.             {
  72.                 return false;
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement