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.Text;
- using System.Threading.Tasks;
- namespace Lab1.Exercises.RealEstateAgency_U1_6
- {
- /// <summary>
- /// Class with methods for working with House.cs class
- /// </summary>
- class HouseUtils
- {
- /// <summary>
- /// Method for finding max house count by street
- /// </summary>
- /// <param name="houseList">given List<house></param>
- /// <returns></returns>
- public static int FindMaxHouseCountByStreet(List<House> houseList)
- {
- int maxHouseCount = 0;
- foreach (House house in houseList)
- {
- int hou = 0;
- for (int i = 0; i < houseList.Count; i++)
- if (house.Street == houseList[i].Street) hou++;
- if (hou > maxHouseCount)
- maxHouseCount = hou;
- }
- return maxHouseCount;
- }
- /// <summary>
- /// Method for filtering house streets with given List<house></house>
- /// </summary>
- /// <param name="houseList">given full List of house</param>
- /// <param name="amount">amount of house street must have to satisfy filter</param>
- /// <returns>returns filtered string list</returns>
- public static List<string> FindHousesByAmount(List<House> houseList, int amount)
- {
- List<string> houseStreets = new List<string>();
- foreach (House house in houseList)
- {
- int hou = 0;
- for (int i = 0; i < houseList.Count; i++)
- {
- if (house.Street == houseList[i].Street) hou++;
- if (hou == amount && !houseStreets.Contains(house.Street)) houseStreets.Add(house.Street);
- }
- }
- return houseStreets;
- }
- /// <summary>
- /// Method for finding oldest house count by Built years
- /// </summary>
- /// <param name="houseList">given List<house></param>
- /// <returns></returns>
- public static List<House> FindHousesByBuildYear(List<House> houseList, int amount)
- {
- List<House> houseBuildYears = new List<House>();
- foreach(House house in houseList)
- {
- if (house.BuildYears==amount)
- {
- houseBuildYears.Add(house);
- }
- }
- /*
- foreach (House house in houseList)
- {
- int hou=0;
- for (int i = 0; i < houseList.Count; i++)
- {
- if (house.BuildYears < houseList[i].BuildYears) hou = house.BuildYears;
- {
- if (house.BuildYears == houseList[i].BuildYears) hou = house.BuildYears;
- }
- }
- }
- */
- return houseBuildYears;
- }
- /// <summary>
- /// Method for filtering oldest house with given List<house></house>
- /// </summary>
- /// <param name="houseList">given full List of house</param>
- /// <param name="amount">amount of house street must have to satisfy filter</param>
- /// <returns>returns filtered string list</returns>
- public static int OldestHouseStreets(List<House> houseList)
- {
- int cur = 30000;
- foreach (House house in houseList)
- {
- if(house.BuildYears < cur)
- {
- cur = house.BuildYears;
- }
- }/*
- //DateTime currentTime = DateTime.Today;
- //DateTime customYearsAgo = currentTime.AddYears(-(int)YearsOld);
- //List<string> hou = new List<string>();
- foreach (House house in houseList)
- {
- int yearsold;
- string adress, type, area;
- for (int i = 0; i < houseList.Count; i++)
- {
- if (house.BuildYears < houseList[i].BuildYears) hou = house.BuildYears; yearsold = currentTime - hou; adress = house.Street; type = house.TypeOfHouse; area = house.HouseArea;
- if (house.BuildYears == amount && !hou.Contains(house.BuildYears)) hou.Add(house.BuildYears);
- }
- }
- */
- return cur;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement