Advertisement
themkss

Untitled

May 2nd, 2023
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.99 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 using Publication as its abstract class
  10.     /// </summary>
  11.     public class Newspaper : Publication, IComparable<Newspaper>, IEquatable<Newspaper>
  12.     {
  13.         public DateTime date { get; set; }
  14.         public int number { get; set; }
  15.         public string MonthAndDayOfRelease { get; set; }
  16.  
  17.         /// <summary>
  18.         /// Constructor for this class
  19.         /// </summary>
  20.         /// <param name="name"></param>
  21.         /// <param name="type"></param>
  22.         /// <param name="publishingPlace"></param>
  23.         /// <param name="yearOfRelease"></param>
  24.         /// <param name="numberOfPages"></param>
  25.         /// <param name="edition"></param>
  26.         /// <param name="date"></param>
  27.         /// <param name="number"></param>
  28.         /// <param name="monthAndDayOfRelease"></param>
  29.         public Newspaper(string name, string type, string publishingPlace, int yearOfRelease, int numberOfPages, int edition,
  30.             DateTime date, int number, string monthAndDayOfRelease) : base(name, type, publishingPlace, yearOfRelease, numberOfPages, edition)
  31.         {
  32.             this.date = date;
  33.             this.number = number;
  34.             this.MonthAndDayOfRelease = monthAndDayOfRelease;
  35.         }
  36.  
  37.         /// <summary>
  38.         /// Implemented IComparable<Newspaper> interface
  39.         /// </summary>
  40.         /// <param name="other"></param>
  41.         /// <returns></returns>
  42.         public int CompareTo(Newspaper other)
  43.         {
  44.             string[] values = MonthAndDayOfRelease.Split(' ');
  45.             int month = int.Parse(values[0]);
  46.             int day = int.Parse(values[1]);
  47.  
  48.             string[] values2 = other.MonthAndDayOfRelease.Split(' ');
  49.             int month2 = int.Parse(values2[0]);
  50.             int day2 = int.Parse(values2[1]);
  51.  
  52.             return DateTime.Compare(new DateTime(this.yearOfRelease, month, day), new DateTime(other.yearOfRelease, month2, day2));
  53.         }
  54.  
  55.         /// <summary>
  56.         /// Implemented IEquatable<Newspaper> interface
  57.         /// </summary>
  58.         /// <param name="other"></param>
  59.         /// <returns></returns>
  60.         public bool Equals(Newspaper other)
  61.         {
  62.             if (this.date.Equals(other.date) && this.number.Equals(other.number) && this.MonthAndDayOfRelease.Equals(other.MonthAndDayOfRelease))
  63.             {
  64.                 return true;
  65.             }
  66.             else
  67.             {
  68.                 return false;
  69.             }
  70.         }
  71.  
  72.         /// <summary>
  73.         /// Overridden ToString() method
  74.         /// </summary>
  75.         /// <returns></returns>
  76.         public override string ToString()
  77.         {
  78.             return String.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8}", this.name, this.type, this.publishingPlace, this.yearOfRelease,
  79.                 this.numberOfPages, this.edition, this.date, this.number, this.MonthAndDayOfRelease);
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement