amarek

Riba

Jul 3rd, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 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 _02._07._2019
  8. {
  9.     class Program
  10.     {
  11.         interface IFishSorter
  12.         {
  13.             double CalculateTotalKg(List<Catch> catchList);
  14.             List<Catch> CreateNewCatchList(List<Catch> catchList);
  15.         }
  16.  
  17.         class Catch
  18.         {
  19.             public double TotalKg { get; private set; }
  20.             public int Quality { get; private set; }
  21.             public String Species { get; private set; }
  22.  
  23.             public Catch(double totalKg, int quality, String species)
  24.             {
  25.                 TotalKg = totalKg; Quality = quality; Species = species;
  26.             }
  27.         }
  28.  
  29.         class TopFishSorter : IFishSorter
  30.         {
  31.             public String Species { get; set; }
  32.             public double MinQuality { get; set; }
  33.  
  34.             public double CalculateTotalKg(List<Catch> catchList) {
  35.                 double mass = 0;
  36.                 for (int i = 0; i < catchList.Count(); i++)
  37.                 {
  38.                     if (catchList[i].Quality > MinQuality)
  39.                     {
  40.                         mass += catchList[i].TotalKg;
  41.                     }
  42.                 }
  43.                 return mass;
  44.             }
  45.  
  46.             public List<Catch> CreateNewCatchList(List<Catch> catchList) {
  47.                 List<Catch> newCatchList = new List<Catch>();
  48.                 for (int i = 0; i < catchList.Count(); i++)
  49.                 {
  50.                     if (catchList[i].Species == Species && catchList[i].Quality >= MinQuality)
  51.                     {
  52.                         newCatchList.Add(catchList[i]);
  53.                     }
  54.                 }
  55.                 return newCatchList;
  56.  
  57.             }
  58.  
  59.         }
  60.  
  61.         void RemoveCatch(List<Catch> Catch, double quality, double mass)
  62.         {
  63.             for (int i = 0; i < Catch.Count(); i++)
  64.             {
  65.                 if (Catch[i].Quality < quality || Catch[i].TotalKg < mass)
  66.                 {
  67.                     Catch.RemoveAt(i);
  68.                 }
  69.             }
  70.         }
  71.  
  72.         static void Main(string[] args)
  73.         {
  74.             List<Catch> fishies = fishingBoat.PullNets();
  75.             int total = fishies.Count();
  76.             RemoveCatch(fishies);
  77.             int newTotal = fishies.Count();
  78.             if ((total - newTotal) > total / 2)
  79.             {
  80.                 Console.Write("Boljeg ulova ima vise od pola.");
  81.             }
  82.             else
  83.             {
  84.                 Console.WriteLine("Loseg ulova ima vise od pola.");
  85.             }
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment