Exemplo n.º 1
0
        public void Register()
        {
            Beach current = null;

            foreach (Beach b in Beach.beaches)
            {
                if (b.name == name)
                {
                    current = b;
                    break;
                }
            }

            if (current != null)
            {
                current.AddOpinion(this);
            }
            else
            {
                Beach.beaches.Add(new Beach(this));
            }
        }
Exemplo n.º 2
0
        /* Формат за плаж:
         * [Име]
         * [Място]
         * [Кола] [Градски транспорт] [Пеша]
         * Заведения: [няма] [до 2] [3-5] [над 5]
         * [гъстота] [замърсеност] [оценка] [бр хора]
         */
        private static void ReadBeach(String[] lines, int offset)
        {
            Beach current = new Beach(lines[offset]);
            current.location = lines[offset + 1];

            // TRANSPORT

            String[] trans = lines[offset + 2].Split(' ');
            try
            {
                current.nCar = int.Parse(trans[0]);
            }
            catch(Exception e)
            {
                MessageBox.Show("IO: " + e.Message, e.GetType().ToString());
                current.nCar = 0;
            }

            try
            {
                current.nCity = int.Parse(trans[1]);
            }
            catch (Exception e)
            {
                MessageBox.Show("IO: " + e.Message, e.GetType().ToString());
                current.nCity = 0;
            }

            try
            {
                current.nFoot = int.Parse(trans[2]);
            }
            catch (Exception e)
            {
                MessageBox.Show("IO: " + e.Message, e.GetType().ToString());
                current.nFoot = 0;
            }

            // FACILITIES

            String[] fac = lines[offset + 3].Split(' ');
            try
            {
                for (int i = 0; i < 4; i++) current.facilties[i] = int.Parse(fac[i]);
            }
            catch (Exception e)
            {
                MessageBox.Show("IO(facilities): " + e.Message, e.GetType().ToString());
            }

            // [гъстота] [замърсеност] [оценка] [бр хора]

            String[] whev = lines[offset + 4].Split(' ');
            try
            {
                current.iDensity = int.Parse(whev[0]);
                current.iPolution = int.Parse(whev[1]);
                current.iGrade = int.Parse(whev[2]);
                current.iCount = int.Parse(whev[3]);
            }
            catch (Exception e)
            {
                MessageBox.Show("IO(last line): " + e.Message, e.GetType().ToString());
            }

            Beach.beaches.Add(current);
        }
Exemplo n.º 3
0
        /* Формат за плаж:
         * [Име]
         * [Място]
         * [Кола] [Градски транспорт] [Пеша]
         * Заведения: [няма] [до 2] [3-5] [над 5]
         * [гъстота] [замърсеност] [оценка] [бр хора]
         */
        private static void WriteBeach(Beach b, StreamWriter writer)
        {
            String data = String.Format("{0}\n{1}\n{2} {3} {4}\n{5} {6} {7} {8}\n{9} {10} {11} {12}\n",
                b.name,
                b.location,
                b.nCar, b.nCity, b.nFoot,
                b.facilties[0], b.facilties[1], b.facilties[2], b.facilties[3],
                b.Density, b.Polution, b.Grade, b.People);

            writer.Write(data);
        }
Exemplo n.º 4
0
        /* Формат за плаж:
         * [Име]
         * [Място]
         * [Кола] [Градски транспорт] [Пеша]
         * Заведения: [няма] [до 2] [3-5] [над 5]
         * [гъстота] [замърсеност] [оценка] [бр хора]
         */
        private static void ReadBeach(String[] lines, int offset)
        {
            Beach current = new Beach(lines[offset]);

            current.location = lines[offset + 1];

            // TRANSPORT

            String[] trans = lines[offset + 2].Split(' ');
            try
            {
                current.nCar = int.Parse(trans[0]);
            }
            catch (Exception e)
            {
                MessageBox.Show("IO: " + e.Message, e.GetType().ToString());
                current.nCar = 0;
            }

            try
            {
                current.nCity = int.Parse(trans[1]);
            }
            catch (Exception e)
            {
                MessageBox.Show("IO: " + e.Message, e.GetType().ToString());
                current.nCity = 0;
            }

            try
            {
                current.nFoot = int.Parse(trans[2]);
            }
            catch (Exception e)
            {
                MessageBox.Show("IO: " + e.Message, e.GetType().ToString());
                current.nFoot = 0;
            }



            // FACILITIES

            String[] fac = lines[offset + 3].Split(' ');
            try
            {
                for (int i = 0; i < 4; i++)
                {
                    current.facilties[i] = int.Parse(fac[i]);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("IO(facilities): " + e.Message, e.GetType().ToString());
            }

            // [гъстота] [замърсеност] [оценка] [бр хора]

            String[] whev = lines[offset + 4].Split(' ');
            try
            {
                current.iDensity  = int.Parse(whev[0]);
                current.iPolution = int.Parse(whev[1]);
                current.iGrade    = int.Parse(whev[2]);
                current.iCount    = int.Parse(whev[3]);
            }
            catch (Exception e)
            {
                MessageBox.Show("IO(last line): " + e.Message, e.GetType().ToString());
            }

            Beach.beaches.Add(current);
        }