Advertisement
themkss

Untitled

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