Ejemplo n.º 1
0
        public static void p4(ref Dictionary <int, BusLine> _obj)
        {
            Console.Write("  Type bus line to change: ");
            var fullline = Console.ReadLine();
            var line     = fullline.Split(new char [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (line.Length != 4)
            {
                throw new Exception("Wrong number of split values while changing.");
            }

            int    _busnumber;
            int    _linenumber;
            double _linelength;

            if (!int.TryParse(line [0], out _busnumber))
            {
                throw new Exception("Wrong format of bus number while changing.");
            }
            if (!int.TryParse(line [2], out _linenumber))
            {
                throw new Exception("Wrong format of line number while changing.");
            }
            if (!double.TryParse(line [3], out _linelength))
            {
                throw new Exception("Wrong format of line length while changing.");
            }
            var buff = new BusLine(_busnumber, line[1], _linenumber, _linelength);

            if (_obj.ContainsKey(buff.BusNumber))
            {
                foreach (var i in _obj.Keys)
                {
                    if (i == buff.BusNumber)
                    {
                        if (_obj [i].Surname == buff.Surname && _obj [i].LineNumber == buff.LineNumber && _obj [i].LineLength == buff.LineLength)
                        {
                            Console.WriteLine("  Existing bus line is equal to typed.");
                            break;
                        }
                        else
                        {
                            _obj [i] = buff;
                            Console.WriteLine("  Existing bus line is changed.");
                            break;
                        }
                    }
                }
            }
            else
            {
                _obj [buff.BusNumber] = buff;
                Console.WriteLine("  New bus line is added.");
            }
        }
Ejemplo n.º 2
0
        public static void p1(ref Dictionary <int, BusLine> _obj)
        {
            if (File.Exists("in.txt"))
            {
                var lines = File.ReadAllLines("in.txt");
                for (int i = 0; i < lines.Length; ++i)
                {
                    var line = lines [i].Split(new char [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    if (line.Length != 4)
                    {
                        throw new Exception("Wrong number of split values while inputting.");
                    }

                    int    _busnumber;
                    int    _linenumber;
                    double _linelength;

                    if (!int.TryParse(line [0], out _busnumber))
                    {
                        throw new Exception("Wrong format of bus number while inputting.");
                    }
                    if (!int.TryParse(line [2], out _linenumber))
                    {
                        throw new Exception("Wrong format of line number while inputting.");
                    }
                    if (!double.TryParse(line [3], out _linelength))
                    {
                        throw new Exception("Wrong format of line length while inputting.");
                    }
                    var buff = new BusLine(_busnumber, line[1], _linenumber, _linelength);
                    _obj [buff.BusNumber] = buff;
                }
                Console.WriteLine("  Dictionary is inputed.");
            }
            else
            {
                throw new Exception("Given file does not exist.");
            }
        }