Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Lab1.Exercises.RealEstateAgency_U1_6
  8. {
  9.     /// <summary>
  10.     /// Class with methods for working with House.cs class
  11.     /// </summary>
  12.     class HouseUtils
  13.     {
  14.         /// <summary>
  15.         /// Method for finding max house count by street
  16.         /// </summary>
  17.         /// <param name="houseList">given List<house></param>
  18.         /// <returns></returns>
  19.         public static int FindMaxHouseCountByStreet(List<House> houseList)
  20.         {
  21.             int maxHouseCount = 0;
  22.             foreach (House house in houseList)
  23.             {
  24.                 int hou = 0;
  25.                 for (int i = 0; i < houseList.Count; i++)
  26.                     if (house.Street == houseList[i].Street) hou++;
  27.  
  28.                 if (hou > maxHouseCount)
  29.                     maxHouseCount = hou;
  30.             }
  31.             return maxHouseCount;
  32.         }
  33.  
  34.        
  35.        
  36.         /// <summary>
  37.         /// Method for filtering house streets with given List<house></house>
  38.         /// </summary>
  39.         /// <param name="houseList">given full List of house</param>
  40.         /// <param name="amount">amount of house street must have to satisfy filter</param>
  41.         /// <returns>returns filtered string list</returns>
  42.         public static List<string> FindHousesByAmount(List<House> houseList, int amount)
  43.         {
  44.             List<string> houseStreets = new List<string>();
  45.  
  46.             foreach (House house in houseList)
  47.             {
  48.                 int hou = 0;
  49.                 for (int i = 0; i < houseList.Count; i++)
  50.                 {
  51.                     if (house.Street == houseList[i].Street) hou++;
  52.                     if (hou == amount && !houseStreets.Contains(house.Street)) houseStreets.Add(house.Street);
  53.                 }
  54.             }
  55.             return houseStreets;
  56.         }
  57.  
  58.         /// <summary>
  59.         /// Method for finding oldest house count by Built years
  60.         /// </summary>
  61.         /// <param name="houseList">given List<house></param>
  62.         /// <returns></returns>
  63.         public static List<House> FindHousesByBuildYear(List<House> houseList, int amount)
  64.         {
  65.  
  66.  
  67.             List<House> houseBuildYears = new List<House>();
  68.  
  69.             foreach(House house in houseList)
  70.             {
  71.                 if (house.BuildYears==amount)
  72.                 {
  73.                     houseBuildYears.Add(house);
  74.                 }
  75.             }
  76.  
  77.             /*
  78.  
  79.             foreach (House house in houseList)
  80.             {
  81.                 int hou=0;
  82.                 for (int i = 0; i < houseList.Count; i++)
  83.                 {
  84.                     if (house.BuildYears < houseList[i].BuildYears) hou = house.BuildYears;
  85.                     {
  86.                         if (house.BuildYears == houseList[i].BuildYears) hou = house.BuildYears;
  87.                     }
  88.                    
  89.                 }
  90.             }
  91.             */
  92.             return houseBuildYears;
  93.         }
  94.  
  95.         /// <summary>
  96.         /// Method for filtering oldest house with given List<house></house>
  97.         /// </summary>
  98.         /// <param name="houseList">given full List of house</param>
  99.         /// <param name="amount">amount of house street must have to satisfy filter</param>
  100.         /// <returns>returns filtered string list</returns>
  101.         public static int OldestHouseStreets(List<House> houseList)
  102.         {
  103.             int cur = 30000;
  104.  
  105.             foreach (House house in houseList)
  106.             {
  107.                 if(house.BuildYears < cur)
  108.                 {
  109.                     cur = house.BuildYears;
  110.                 }
  111.             }/*
  112.            
  113.            
  114.            
  115.            
  116.             //DateTime currentTime = DateTime.Today;
  117.             //DateTime customYearsAgo = currentTime.AddYears(-(int)YearsOld);
  118.  
  119.             //List<string> hou = new List<string>();
  120.  
  121.            
  122.             foreach (House house in houseList)
  123.             {
  124.                 int  yearsold;
  125.                 string adress, type, area;
  126.                 for (int i = 0; i < houseList.Count; i++)
  127.                 {
  128.  
  129.                     if (house.BuildYears < houseList[i].BuildYears) hou = house.BuildYears;  yearsold = currentTime - hou;  adress = house.Street; type = house.TypeOfHouse; area = house.HouseArea;
  130.                     if (house.BuildYears == amount && !hou.Contains(house.BuildYears)) hou.Add(house.BuildYears);
  131.                 }
  132.             }
  133.             */
  134.  
  135.  
  136.             return cur;
  137.         }
  138.  
  139.  
  140.  
  141.    
  142.  
  143.     }
  144.  
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement