Advertisement
themkss

Untitled

May 2nd, 2023
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.06 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.     /// Register class
  10.     /// </summary>
  11.     public class LibraryRegister
  12.     {
  13.         private List<Publication> publications;
  14.         public string name { get; set; }
  15.         public string address { get; set; }
  16.         public string phoneNumber { get; set; }
  17.  
  18.         /// <summary>
  19.         /// Constructor 1 for this class
  20.         /// </summary>
  21.         /// <param name="publications"></param>
  22.         /// <param name="name"></param>
  23.         /// <param name="address"></param>
  24.         /// <param name="phoneNumber"></param>
  25.         public LibraryRegister(List<Publication> publications, string name, string address, string phoneNumber)
  26.         {
  27.             for (int i = 0; i < publications.Count; i++)
  28.             {
  29.                 this.publications.Add(publications[i]);
  30.             }
  31.  
  32.             this.name = name;
  33.             this.address = address;
  34.             this.phoneNumber = phoneNumber;
  35.         }
  36.  
  37.         /// <summary>
  38.         /// Constructor 2 for this class
  39.         /// </summary>
  40.         /// <param name="Publications"></param>
  41.         public LibraryRegister(List<Publication> Publications)
  42.         {
  43.             this.publications = new List<Publication>();
  44.  
  45.             for (int i = 0; i < Publications.Count(); i++)
  46.             {
  47.                 this.publications.Add(Publications[i]);
  48.             }
  49.         }
  50.  
  51.         /// <summary>
  52.         /// Constructor 3 for this class (empty)
  53.         /// </summary>
  54.         public LibraryRegister()
  55.         {
  56.             this.publications = new List<Publication>();
  57.         }
  58.  
  59.         /// <summary>
  60.         /// Method to add a value to the Publication List
  61.         /// </summary>
  62.         /// <param name="publication"></param>
  63.         public void Add(Publication publication)
  64.         {
  65.             this.publications.Add(publication);
  66.         }
  67.  
  68.         /// <summary>
  69.         /// Method to return a value of how many Publications are in the list
  70.         /// </summary>
  71.         /// <returns></returns>
  72.         public int Count()
  73.         {
  74.             return this.publications.Count;
  75.         }
  76.  
  77.         /// <summary>
  78.         /// Method to return a Publication from the list by the index
  79.         /// </summary>
  80.         /// <param name="id"></param>
  81.         /// <returns></returns>
  82.         public Publication Get(int id)
  83.         {
  84.             return this.publications[id];
  85.         }
  86.  
  87.         /// <summary>
  88.         /// Method to find the highest edition Publicatiosn in the list
  89.         /// </summary>
  90.         /// <returns></returns>
  91.         public List<Publication> FindHighestEdition()
  92.         {
  93.             List<Publication> list = new List<Publication>();
  94.             string[] types = { "Book", "Journal", "Newspaper" };
  95.  
  96.             for (int i = 0; i < 3; i++)
  97.             {
  98.                 int max = 0;
  99.                 int id = -1;
  100.                 string check = types[i];
  101.  
  102.                 for (int j = 0; j < this.publications.Count; j++)
  103.                 {
  104.                     if (this.publications[j].type.Equals(check) && max < this.publications[j].edition)
  105.                     {
  106.                         max = this.publications[j].edition;
  107.                         id = j;
  108.                     }
  109.                 }
  110.                 list.Add(this.publications[id]);
  111.             }
  112.  
  113.             return list;
  114.         }
  115.  
  116.         /// <summary>
  117.         /// Sort method
  118.         /// </summary>
  119.         public void Sort()
  120.         {
  121.             for (int i = 0; i < this.publications.Count(); i++)
  122.             {
  123.                 for (int j = i + 1; j < this.publications.Count(); j++)
  124.                 {
  125.                     if (this.publications[i].CompareTo(this.publications[j]) > 0)
  126.                     {
  127.                         Publication p = this.publications[i];
  128.                         this.publications[i] = this.publications[j];
  129.                         this.publications[j] = p;
  130.                     }
  131.                 }
  132.             }
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement