示例#1
0
        public static int CountGuides(City city)
        {
            int guides = 0;

            for (int i = 0; i < city.Museums.Count; i++)
            {
                Museum museum = city.Museums.GetPlace(i) as Museum;
                if (museum.HasGuide)
                {
                    guides++;
                }
            }
            return(guides);
        }
示例#2
0
        public static void ReadCityData(City[] cities, string fName)
        {
            using (StreamReader reader = new StreamReader(fName))
            {
                int cityIndex = GetCityIndex(cities, reader.ReadLine());
                cities[cityIndex].ResponsiblePerson = reader.ReadLine();
                string line = null;

                while (null != (line = reader.ReadLine()))
                {
                    string[] data   = line.Split(',');
                    int      count  = 1;
                    string   name   = data[count++];
                    string   adress = data[count++];
                    int      year   = int.Parse(data[count++]);

                    switch (data[0].ToLower())
                    {
                    case Monument.Id:
                        string   author      = data[count++];
                        string   intendedFor = data[count++];
                        Monument monument    = new Monument(name, adress, year, author, intendedFor);
                        if (!cities[cityIndex].Monuments.Contains(monument))
                        {
                            cities[cityIndex].Monuments.AddPlace(monument);
                        }
                        break;

                    case Museum.Id:
                        string type    = data[count++];
                        bool[] worksOn = new bool[7];
                        for (int i = 0; i < 7; i++)
                        {
                            worksOn[i] = bool.Parse(data[count++]);
                        }
                        data[count] = data[count].Replace('.', ',');
                        double ticketPrice = double.Parse(data[count++]);
                        bool   hasGuide    = bool.Parse(data[count++]);
                        Museum museum      = new Museum(name, adress, year, type, worksOn, ticketPrice, hasGuide);
                        if (!cities[cityIndex].Museums.Contains(museum))
                        {
                            cities[cityIndex].Museums.AddPlace(museum);
                        }
                        break;
                    }
                }
            }
        }