Ejemplo n.º 1
0
        private static void AddFish(FishRegister myFishRegister, string fisher, Fish fish, Location location)
        {
            Fisherman fisherMan = myFishRegister.Fishers.Find(x => x.Name == fisher);

            if (fisherMan != null)
            {
                myFishRegister.FishingEventList.Add(new FishingEvent(fisherMan, fish, location));
            }
            else
            {
                Console.WriteLine("Fisher can't be found. Typo in the name?");
            }
            Console.WriteLine($"{fisherMan.Name} got a new fish!");
            Console.WriteLine(fish.ToString());
            Console.WriteLine(location.ToString() + "\n");
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // create a new FishRegister and add some fishers to it
            FishRegister myFishRegister = new FishRegister();

            AddFisher(myFishRegister, new Fisherman("Tatu Alatalo", "0401234567"));
            AddFisher(myFishRegister, new Fisherman("Matti Meikäläinen", "0407654321"));
            // add some fishes to FishRegister
            AddFish(myFishRegister, "Tatu Alatalo", new Fish("Pike", 0.62, 1.52), new Location("Pyhäjoki", "Kärsämäki"));
            AddFish(myFishRegister, "Matti Meikäläinen", new Fish("Pike", 0.98, 3.15), new Location("Pyhäjärvi", "Pyhäjärvi"));
            AddFish(myFishRegister, "Tatu Alatalo", new Fish("Salmon", 0.51, 1.12), new Location("Kalajoki", "Ylivieska"));
            // print FishRegister
            PrintMyFishApp(myFishRegister);
            // sort fishes by weight and print the register
            PrintBiggestFishes(myFishRegister);
        }
Ejemplo n.º 3
0
 private static void PrintMyFishApp(FishRegister myFishRegister)
 {
     Console.WriteLine("\n*** All the fishes sorted by fishermen: ***\n");
     for (int i = 0; i < myFishRegister.Fishers.Count; i++)
     {
         string fisherName = myFishRegister.Fishers[i].Name;
         var    hold       = myFishRegister.FishingEventList.FindAll(x => x.Fisher.Name == fisherName).ToArray();
         if (hold != null)
         {
             foreach (var item in hold)
             {
                 Console.WriteLine(item.Fish.ToString());
                 Console.WriteLine(item.Location.ToString());
                 Console.WriteLine(item.Fisher.ToString() + "\n");
             }
         }
     }
 }
Ejemplo n.º 4
0
        private static void PrintBiggestFishes(FishRegister myFishRegister)
        {
            FishRegister holderRegister = new FishRegister();

            holderRegister = myFishRegister;
            var hold = holderRegister.FishingEventList.OrderByDescending(x => x.Fish.Weight).ToList(); // tää oli tehtävän vaikein juttu. Kätevää ja toimii

            if (hold != null)
            {
                holderRegister.FishingEventList = hold;
            }
            Console.WriteLine("\n*** All fishes sorted by weight in the Fishregister: ***\n");
            foreach (var item in holderRegister.FishingEventList)
            {
                Console.WriteLine(item.Fish.ToString());
                Console.WriteLine(item.Location.ToString());
                Console.WriteLine(item.Fisher.ToString() + "\n");
            }
        }
Ejemplo n.º 5
0
 private static void AddFisher(FishRegister myFishRegister, Fisherman fisher)
 {
     myFishRegister.Fishers.Add(fisher);
     Console.WriteLine($"Fisher {fisher.Name} added into the Fishregister.\n");
 }