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>
- /// Register class
- /// </summary>
- public class LibraryRegister
- {
- private List<Publication> publications;
- public string name { get; set; }
- public string address { get; set; }
- public string phoneNumber { get; set; }
- /// <summary>
- /// Constructor 1 for this class
- /// </summary>
- /// <param name="publications"></param>
- /// <param name="name"></param>
- /// <param name="address"></param>
- /// <param name="phoneNumber"></param>
- public LibraryRegister(List<Publication> publications, string name, string address, string phoneNumber)
- {
- for (int i = 0; i < publications.Count; i++)
- {
- this.publications.Add(publications[i]);
- }
- this.name = name;
- this.address = address;
- this.phoneNumber = phoneNumber;
- }
- /// <summary>
- /// Constructor 2 for this class
- /// </summary>
- /// <param name="Publications"></param>
- public LibraryRegister(List<Publication> Publications)
- {
- this.publications = new List<Publication>();
- for (int i = 0; i < Publications.Count(); i++)
- {
- this.publications.Add(Publications[i]);
- }
- }
- /// <summary>
- /// Constructor 3 for this class (empty)
- /// </summary>
- public LibraryRegister()
- {
- this.publications = new List<Publication>();
- }
- /// <summary>
- /// Method to add a value to the Publication List
- /// </summary>
- /// <param name="publication"></param>
- public void Add(Publication publication)
- {
- this.publications.Add(publication);
- }
- /// <summary>
- /// Method to return a value of how many Publications are in the list
- /// </summary>
- /// <returns></returns>
- public int Count()
- {
- return this.publications.Count;
- }
- /// <summary>
- /// Method to return a Publication from the list by the index
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public Publication Get(int id)
- {
- return this.publications[id];
- }
- /// <summary>
- /// Method to find the highest edition Publicatiosn in the list
- /// </summary>
- /// <returns></returns>
- public List<Publication> FindHighestEdition()
- {
- List<Publication> list = new List<Publication>();
- string[] types = { "Book", "Journal", "Newspaper" };
- for (int i = 0; i < 3; i++)
- {
- int max = 0;
- int id = -1;
- string check = types[i];
- for (int j = 0; j < this.publications.Count; j++)
- {
- if (this.publications[j].type.Equals(check) && max < this.publications[j].edition)
- {
- max = this.publications[j].edition;
- id = j;
- }
- }
- list.Add(this.publications[id]);
- }
- return list;
- }
- /// <summary>
- /// Sort method
- /// </summary>
- public void Sort()
- {
- for (int i = 0; i < this.publications.Count(); i++)
- {
- for (int j = i + 1; j < this.publications.Count(); j++)
- {
- if (this.publications[i].CompareTo(this.publications[j]) > 0)
- {
- Publication p = this.publications[i];
- this.publications[i] = this.publications[j];
- this.publications[j] = p;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement