Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace LB4_V2
- {
- /// <summary>
- /// Data Class using Publication as its abstract class
- /// </summary>
- public class Newspaper : Publication, IComparable<Newspaper>, IEquatable<Newspaper>
- {
- public DateTime date { get; set; }
- public int number { get; set; }
- public string MonthAndDayOfRelease { get; set; }
- /// <summary>
- /// Constructor for this class
- /// </summary>
- /// <param name="name"></param>
- /// <param name="type"></param>
- /// <param name="publishingPlace"></param>
- /// <param name="yearOfRelease"></param>
- /// <param name="numberOfPages"></param>
- /// <param name="edition"></param>
- /// <param name="date"></param>
- /// <param name="number"></param>
- /// <param name="monthAndDayOfRelease"></param>
- public Newspaper(string name, string type, string publishingPlace, int yearOfRelease, int numberOfPages, int edition,
- DateTime date, int number, string monthAndDayOfRelease) : base(name, type, publishingPlace, yearOfRelease, numberOfPages, edition)
- {
- this.date = date;
- this.number = number;
- this.MonthAndDayOfRelease = monthAndDayOfRelease;
- }
- /// <summary>
- /// Implemented IComparable<Newspaper> interface
- /// </summary>
- /// <param name="other"></param>
- /// <returns></returns>
- public int CompareTo(Newspaper other)
- {
- string[] values = MonthAndDayOfRelease.Split(' ');
- int month = int.Parse(values[0]);
- int day = int.Parse(values[1]);
- string[] values2 = other.MonthAndDayOfRelease.Split(' ');
- int month2 = int.Parse(values2[0]);
- int day2 = int.Parse(values2[1]);
- return DateTime.Compare(new DateTime(this.yearOfRelease, month, day), new DateTime(other.yearOfRelease, month2, day2));
- }
- /// <summary>
- /// Implemented IEquatable<Newspaper> interface
- /// </summary>
- /// <param name="other"></param>
- /// <returns></returns>
- public bool Equals(Newspaper other)
- {
- if (this.date.Equals(other.date) && this.number.Equals(other.number) && this.MonthAndDayOfRelease.Equals(other.MonthAndDayOfRelease))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// Overridden ToString() method
- /// </summary>
- /// <returns></returns>
- public override string ToString()
- {
- return String.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8}", this.name, this.type, this.publishingPlace, this.yearOfRelease,
- this.numberOfPages, this.edition, this.date, this.number, this.MonthAndDayOfRelease);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement