Exemplo n.º 1
0
        //methods
        static public void CreateFishingEvent(Fisher fisher, Fish fish, Location location, Collections Registry)
        {
            //id creation
            Name = name + ind.ToString();
            ind++;

            //object creation
            Registry.FishingEventDict.Add(Name, new FishingEvent(fisher, fish, location));
        }
Exemplo n.º 2
0
 //constructors
 private FishingEvent(Fisher fisher, Fish fish, Location location)
 {
     this.fisher   = fisher;
     this.fish     = fish;
     this.location = location;
     Console.WriteLine("\nFisher : {0} got a new fish", fisher.Name);
     Console.WriteLine(" - specie : {0} {1} cm {2} kg", fish.Specie, fish.Lenght, fish.Weight);
     Console.WriteLine(" - place : {0}", location.Place);
     Console.WriteLine(" - location : {0}", location.LocationS);
 }
        static void Main(string[] args)
        {
            //init collections
            Collections Registry = new Collections();

            //creating fisher
            Fisher.CreateFisher("Kirsi Kernel", "020-12345678", Registry);

            //creating 1st event as per assignment
            string fisher = "Kirsi Kernel";

            Location.CreateLocation("The Lake of Jyvaskyla", "Jyvaskyla", Registry);
            string location = "The Lake of Jyvaskyla";
            Fish   f        = Fish.CreateFish("pike", 120, 4.5, Registry);

            try
            {
                FishingEvent.CreateFishingEvent(Registry.Fisherlist.FirstOrDefault(x => x.Name == fisher), f, Registry.Locationlist.FirstOrDefault(x => x.Place == location), Registry);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            //creating 2nd event as per assignment
            fisher = "Kirsi Kernel";
            Location.CreateLocation("River Teno", "The Northern edge of Finland", Registry);
            location = "River Teno";
            f        = Fish.CreateFish("salmon", 190, 13.2, Registry);
            try
            {
                FishingEvent.CreateFishingEvent(Registry.Fisherlist.FirstOrDefault(x => x.Name == fisher), f, Registry.Locationlist.FirstOrDefault(x => x.Place == location), Registry);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            //printing fishing events per fisher
            List <string> fisherNames = new List <string>();

            Console.WriteLine("\nAll fish in the register:");

            foreach (FishingEvent fe in Registry.FishingEventDict.Values)
            {
                //prints only once fisher's name
                if (!fisherNames.Contains(fe.fisher.Name))
                {
                    fisherNames.Add(fe.fisher.Name);
                    Console.WriteLine("\nFisherman {0} has got following fish:\n", fe.fisher.Name);
                }
                //then lists fishs she has fished
                if (fisherNames.Contains(fe.fisher.Name))
                {
                    Console.WriteLine(" - specie: {0} {1} cm {2} kg", fe.fish.Specie, fe.fish.Lenght, fe.fish.Weight);
                    Console.WriteLine(" - place: {0}", fe.location.Place);
                    Console.WriteLine(" - location {0}\n", fe.location.LocationS);
                }
            }

            //printing fish info sorted by weight desc
            //fishing events to sortable list
            List <FishingEvent> feList = new List <FishingEvent>();

            foreach (FishingEvent fe in Registry.FishingEventDict.Values)
            {
                feList.Add(fe);
            }
            //sorting list
            feList.Sort((x, y) => y.fish.Weight.CompareTo(x.fish.Weight));
            //printing sorted list
            Console.WriteLine("Sorted register\n\n***All fish in the Fish-register");
            foreach (FishingEvent fe in feList)
            {
                Console.WriteLine();
                fe.PrintFishingEventInfo();
            }
            Console.WriteLine();
        }